溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

nginx 轉(zhuǎn)發(fā)配置

發(fā)布時間:2020-07-02 06:18:47 來源:網(wǎng)絡(luò) 閱讀:472 作者:獨孤環(huán)宇 欄目:建站服務(wù)器

Nginx配置proxy_pass轉(zhuǎn)發(fā)的/路徑問題

在nginx中配置proxy_pass時,如果是按照^~匹配路徑時,要注意proxy_pass后的url最后的/,當(dāng)加上了/,相當(dāng)于是絕對根路徑,則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

當(dāng)然,我們可以用如下的rewrite來實現(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


向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI