Nginx配置proxy_pass转发的/路径问题

来源:互联网 发布:淘宝宠物狗怎么快递 编辑:程序博客网 时间:2024/04/30 14:00

<span style="font-family: Arial, Helvetica, sans-serif;">参考:http://wangwei007.blog.51cto.com/68019/1103734</span>

在nginx中配置proxy_pass时,如果是按照^~匹配路径时,要注意proxy_pass后的url最后的/,当加上了/,相当于是绝对根路径,则nginx不会把location中匹配的路径部分代理走;如果没有/,则会把匹配的路径部分也给代理走。

location ^~ /static_js/
{
proxy_cache js_cache;
proxy_set_header Host js.test.com;
proxy_pass http://js.test.com/;
}

如上面的配置,如果请求的url是http://servername/static_js/test.html
会被代理成http://js.test.com/test.html

而如果这么配置

location ^~ /static_js/
{
proxy_cache js_cache;
proxy_set_header Host js.test.com;
proxy_pass http://js.test.com;
}

则会被代理到http://js.test.com/static_js/test.htm

当然,我们可以用如下的rewrite来实现/的功能

location ^~ /static_js/
{
proxy_cache js_cache;
proxy_set_header Host js.test.com;
rewrite /static_js/(.+)$ /$1 break;
proxy_pass http://js.test.com;
}
 

本文出自 “王伟” 博客,请务必保留此出处http://wangwei007.blog.51cto.com/68019/1103734



注意:在nginx的upstream做负载均衡时要用ip或者远程主机名,不能使用localhost。

C:\Users\Steve\Desktop\ssh>pscp -i C:\Users\Steve\Desktop\ssh\puttyKey\key\steven.ppk G:\eclipse\workspace\project\shopping\target\shopping.war root@www.jackal.cn:///home/data6/projectPassphrase for key "rsa-key-20140404":shopping.war              | 23908 kB | 154.3 kB/s | ETA: 00:00:00 | 100%


0 0
原创粉丝点击