Nginx的代理功能太完善了,我们看看proxy_redirect参数的作用。

案例说明:
要做一个html.aslibra.com的域名处理很多网站的html内容,当然是后端的服务器了,目录分析
html.zcom.com/img.aslibra.com/
html.zcom.com/css.aslibra.com/
访问的域名是该目录下的域名,那前端nginx的配置应该类似这样: server {
server_name img.aslibra.com;
location / {
rewrite ^(.*) /$http_host$ break;
proxy_set_header Host html.aslibra.com;
proxy_pass http://cache-89;
}
} 但这样访问目录时如果没有以“/”结尾,则服务器会返回301redirect: [root@aslibra ~]# curl -I http://img.aslibra.com/www
HTTP/1.1 Moved Permanently
Server: nginx/0.7.
Date: Tue, Jul :: GMT
Connection: keep-alive
Location: http://html.aslibra.com/img.aslibra.com/www/ html.aslibra.com这个域名并非公布的域名,返回给客户端是会自然产生错误的
Nginx可以很好的处理这个问题: server {
server_name img.aslibra.com;
location / {
rewrite ^(.*) /$http_host$ break;
proxy_set_header Host html.aslibra.com;
proxy_pass http://cache-89;
proxy_redirect http://html.aslibra.com/img.aslibra.com/ /;
}
} 加一行proxy_redirect后,正常了: [root@aslibra ~]# curl -I http://img.aslibra.com/www
HTTP/1.1 Moved Permanently
Server: nginx/0.7.
Date: Tue, Jul :: GMT
Content-Type: text/html
Location: http://img.aslibra.com/www/
Connection: keep-alive
Content-Length:
Expires: Tue, Jul :: GMT
Cache-Control: max-age= 就这么样就ok啦~
不过貌似不支持变量出现在地址里,这个就郁闷了,必须指定相应域名。
对于多个域名匹配的server,redirect设置不能写作’/'了,否则会用第一个域名作为redirect域名
可以写几个匹配规则: proxy_redirect http://html.aslibra.com/img.aslibra.com/ http://img.aslibra.com/;
proxy_redirect http://html.aslibra.com/css.aslibra.com/ http://css.aslibra.com/;

proxy_redirect参数的作用的更多相关文章

  1. jQuery ajax的traditional参数的作用///////////////////////////////////zzzzzzzzzzz

    jQuery ajax的traditional参数的作用 i33 发布时间: 2013/04/03 10:05 阅读: 9859 收藏: 9 点赞: 1 评论: 0 一般的,可能有些人在一个参数有多个 ...

  2. 关于context:component-scan配置中use-default-filters参数的作用

    参考了多篇文章都说明了use-default-filters参数的基本用途,但有些主要点没有说到,这里补充记录下: <context:component-scan base-package=&q ...

  3. Dos del参数与作用(/f/s/q)

    Dos del参数与作用(/f/s/q) C:\Documents and Settings>del /? 删除一个或数个文件. DEL [/P] [/F] [/S] [/Q] [/A[[:]a ...

  4. Jquery中Ajax异步请求中的async参数的作用

    之前不知道这个参数的作用,上网找了前辈的博客,在此收录到自己的博客,希望能帮到更多的朋友: test.html <a href="javascript:void(0)" on ...

  5. pytorch autograd backward函数中 retain_graph参数的作用,简单例子分析,以及create_graph参数的作用

    retain_graph参数的作用 官方定义: retain_graph (bool, optional) – If False, the graph used to compute the grad ...

  6. 神经网络中w,b参数的作用(为何需要偏置b的解释)

    http://blog.csdn.net/xwd18280820053/article/details/70681750 可视图讲解神经元w,b参数的作用 在我们接触神经网络过程中,很容易看到就是这样 ...

  7. mysql中,创建表的时候指定if not exists参数的作用?

    需求说明: 在创建表的时候,如果指定if not exists语句,有什么作用,在此做个实验,并且官方手册, 理解下这个参数的作用. 操作过程: 1.创建测试表test01 mysql> cre ...

  8. mysql的jdbc.url携带allowMultiQueries=true参数的作用及其原理

    如下配置 jdbc.url=jdbc:mysql://127.0.0.1:3306/chubb_2?autoReconnect=true&useUnicode=true&charact ...

  9. backward的gradient参数的作用

    backward的gradient参数的作用 待办 https://zhuanlan.zhihu.com/p/29904755 https://zhuanlan.zhihu.com/p/2992309 ...

随机推荐

  1. 【树链剖分】【树状数组】【最近公共祖先】【块状树】bzoj3631 [JLOI2014]松鼠的新家

    裸题,树状数组区间修改+单点查询.当然要稍微讨论一下链的左右端点是否修改的情况咯. #include<cstdio> #include<algorithm> #include& ...

  2. 微服务之SpringCloud实战(四):SpringCloud Eureka源码分析

    Eureka源码解析: 搭建Eureka服务的时候,我们会再SpringBoot启动类加上@EnableEurekaServer的注解,这个注解做了一些什么,我们一起来看. 点进@EnableEure ...

  3. Sublime | 编辑工具Sublime的使用小结

    文章目录 Sublime Package & Usage MarkdownEditing MarkdownPreview Usage Key Bindings Setting (语法高亮和ma ...

  4. angularjs+requirejs整合

    通过requirejs的配置让angularJS可以正常运行.以下是配置的步骤: 环境需求 require.js angular.js 有了这两文件,就可以进行下一步了,具体将文件放到哪个目录,可以跟 ...

  5. Maven多模块项目单独编译子模块项目时报错:Failed to execute goal on project/Could not resolve dependencies for project

    背景:常规的父子项目搭建的工程,参考:http://www.cnblogs.com/EasonJim/p/6863987.html 解决方法: 1.需要把parent工程,也就是package是pom ...

  6. cssz中<a>标签鼠标选中去除选中边框

    IE: <a href="#" hidefocus="true"></a> 非IE: a:focus { outline:none; } ...

  7. ZooKeeper服务器是用Java创建的,它在JVM上运行。

    ZooKeeper服务器是用Java创建的,它在JVM上运行. 创建配置文件 使用命令 vi conf/zoo.cfg 和所有以下参数设置为起点,打开名为 conf/zoo.cfg 的配置文件. $ ...

  8. java工具类获取properties文件的配置

    import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.i ...

  9. asp.net 视图引擎归类

    1. ASPX View Engine 第一个也是我们最熟悉的---aspx,相信做过WebForm开发对Aspx都比较了解: 小示例: <%@ Control Inherits="S ...

  10. [Java基础] java多线程关于消费者和生产者

    多线程: 生产与消费 1.生产者Producer生产produce产品,并将产品放到库存inventory里:同时消费者Consumer从库存inventory里消费consume产品. 2.库存in ...