Nginx配置轉發


nginx location proxy_pass 后面的url 加與不加/的區別

 在nginx中配置proxy_pass時,當在后面的url加上了/,相當於是絕對根路徑,則nginx不會把location中匹配的路徑部分代理走;如果沒有/,則會把匹配的路徑部分也給代理走。

 首先是location進行的是模糊匹配

1)沒有“/”時,location /abc/def可以匹配/abc/defghi請求,也可以匹配/abc/def/ghi等
2)而有“/”時,location /abc/def/不能匹配/abc/defghi請求,只能匹配/abc/def/anything這樣的請求

下面四種情況分別用http://luxingda.top/py/test 進行訪問。

第一種:

location  /py/ {

proxy_pass http://127.0.0.1:5000/;

}

結論:會被代理到http://127.0.0.1:5000/test  這個url

第二種(相對於第一種,最后少一個 /)

location  /py/ {

proxy_pass http://127.0.0.1:5000
; }

 

結論:會被代理到http://127.0.0.1:5000/py/test這個url

第三種:

location  /py/ {

proxy_pass http://127.0.0.1:5000/py/;

}

結論:會被代理到http://127.0.0.1:5000/py/test這個url。

第四種(相對於第三種,最后少一個 / ):

location  /py/ {

proxy_pass http://127.0.0.1:5000/py;

}

結論:會被代理到http://127.0.0.1:5000/pytest這個url

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM