Nginx配置proxy_pass轉發的/路徑問題 國內私募機構九鼎控股打造APP,來就送 20元現金領取地址:http://jdb.jiudingcapital.com/phone.html 內部邀請碼:C8E245J (不寫邀請碼,沒有現金送) 國內私募機構九鼎控股打造,九鼎投資是在全國股份轉讓系統掛牌的公眾公司,股票代碼為430719,為“中國PE第一股”,市值超1000億元。 ------------------------------------------------------------------------------------------------------------------------------------------------------------------ Nginx配置proxy_pass轉發的/路徑問題 在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; }