Nginx的proxy_redirect作用
2012-02-29 21:19
483 查看
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$1 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 301 Moved Permanently
Server: nginx/0.7.59
Date: Tue, 21 Jul 2009 15:28:58 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$1 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 301 Moved Permanently
Server: nginx/0.7.59
Date: Tue, 21 Jul 2009 15:23:49 GMT
Content-Type: text/html
Location: http://img.aslibra.com/www/ Connection: keep-alive
Content-Length: 185
Expires: Tue, 21 Jul 2009 16:23:49 GMT
Cache-Control: max-age=3600
就这么样就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/;[/quote]
Nginx的proxy_redirect作用
技术分享 » Nginx | 阅读(5342) | 评论(1)Jul212009Nginx的代理功能太完善了,我们看看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$1 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 301 Moved Permanently
Server: nginx/0.7.59
Date: Tue, 21 Jul 2009 15:28:58 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$1 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 301 Moved Permanently
Server: nginx/0.7.59
Date: Tue, 21 Jul 2009 15:23:49 GMT
Content-Type: text/html
Location: http://img.aslibra.com/www/ Connection: keep-alive
Content-Length: 185
Expires: Tue, 21 Jul 2009 16:23:49 GMT
Cache-Control: max-age=3600
就这么样就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/;[/quote]
相关文章推荐
- nginx配置中proxy_redirect的作用(转)
- nginx配置中proxy_redirect的作用(转)
- nginx配备中proxy_redirect的作用(转)
- Nginx的proxy_redirect作用
- nginx配置中proxy_redirect的作用(转)
- 关于nginx参数proxy_redirect的设置
- nginx的proxy_redirect
- nginx 反向代理设置中的proxy_redirect
- nginx 之 proxy_redirect详解
- nginx 负载均衡配置以及用proxy_redirect替换URL
- nginx中proxy_set_header Host $host的作用
- nginx做反向代理proxy_pass,proxy_redirect的使用
- nginx中proxy_set_header Host $host的作用
- 【转】nginx中proxy_set_header Host $host的作用
- nginx中proxy_set_header 的作用
- proxy_redirect参数的作用
- nginx中proxy_set_header Host $host;的作用
- nginx中proxy_set_header Host $host的作用
- nginx做反向代理proxy_pass,proxy_redirect的使用
- Nginx中ip_hash负载均衡中location的proxy_pass配置与说明