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

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

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

location ^~ /static_js/ 

proxy_cache js_cache; 
proxy_set_header Host js.test.com; 
proxy_pass http://js.test.com/
}url

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

而若是这么配置server

location ^~ /static_js/ 

proxy_cache js_cache; 
proxy_set_header Host js.test.com; 
proxy_pass http://js.test.com
}htm

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

固然,咱们能够用以下的rewrite来实现/的功能get

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
it

 

http://www.cnblogs.com/AloneSword/p/3673829.htmlio

相关文章
相关标签/搜索