Nginx配置proxy_pass轉(zhuǎn)發(fā)的/路徑問題
在nginx中配置proxy_pass時(shí),如果是按照^~匹配路徑時(shí),要注意proxy_pass后的url最后的/,當(dāng)加上了/,相當(dāng)于是絕對(duì)根路徑,則nginx不會(huì)把location中匹配的路徑部分代理走;如果沒有/,則會(huì)把匹配的路徑部分也給代理走。
location ^~ /static_js/
{
proxy_cache js_cache;
proxy_set_header Host js.test.com;
proxy_pass http://js.test.com/;
}
如上面的配置,如果請(qǐng)求的url是http://servername/static_js/test.html
會(huì)被代理成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;
}
則會(huì)被代理到http://js.test.com/static_js/test.htm
當(dāng)然,我們可以用如下的rewrite來實(shí)現(xiàn)/的功能
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;
}
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。