pass转发的/路径问题

在nginx中配置proxy_pass时,如果是按照^~匹配路径时,要注意proxy_pass后的url最后的/,当加上了/,相当于是绝对根路径,则nginx不会把location中匹配的路径部分代理走;如果没有/,则会把匹配的路径部分也给代理走。
 
location ^~ /static_js/
{
proxy_cache js_cache;
proxy_set_header Host js.88181.com;
proxy_pass ;
}
 
如上面的配置,如果请求的url是
 会被代理成
 
而如果这么配置
 
location ^~ /static_js/
{
proxy_cache js_cache;
proxy_set_header Host js.88181.com;
proxy_pass ;
}
 
则会被代理到
 
当然,我们可以用如下的rewrite来实现/的功能
 
location ^~ /static_js/
{
proxy_cache js_cache;
proxy_set_header Host js.88181.com;
rewrite /static_js/(.+)$ /$1 break;
proxy_pass ;
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/74d2632d98b97d1ae8f664b2c6f9d2f5.html