一,在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
而如果這麼配置
proxy_pass http://js.test.com;
如上面的配置,如果請求的url是http://servername/static_js/test.html
則會被代理到http://js.test.com/static_js/test.htm
二,關于proxy_pass配置的uri問題
你不想nginx對你的URI請求有任何形式的修改,那麼,proxy_pass的配置中就不應該有任何URI部分。
舉個例子,nginx伺服器IP為10.0.0.20,它的配置不含URI:
location /first/second/ {
proxy_pass http://10.0.0.30:90;
}
那麼,
原:http://10.0.0.20/first/second/test.html
轉:http://10.0.0.30:90/first/second/test.html
如果配置成含URI:
proxy_pass http://10.0.0.30:90/myuri;
原: http://10.0.0.20/first/second/test.html
轉:http://10.0.0.30:90/myuri/test.html
簡單地說,配置了URI之後,跳轉行為可能會令你感到莫名其妙。
本文轉自 leejia1989 51CTO部落格,原文連結:http://blog.51cto.com/leejia/1198030,如需轉載請自行聯系原作者