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