7, nginx location proxy_pass 後面的url 加與不加/的區別
阿新 • • 發佈:2020-07-26
192.168.0.11--->nginx location proxy_pass 後面的url 加與不加/的區別: location /static { proxy_pass http://192.168.0.13:81; } location /static { proxy_pass http://192.168.0.13:81/; } location /static/ { proxy_pass http://192.168.0.13:81; } location /static/ { proxy_pass http://192.168.0.13:81/; } 這裡我們分4種情況討論: 這裡我們請求的網站為:192.168.0.11:80/static/a.html 第一種: location後沒有/ 轉發網站沒有/ #192.168.0.11->server name # :80 ---------> port #/statc ------->location #/a.html ------>proxy_pass location /static { proxy_pass http://192.168.0.13:81; } 最後網址經過nginx轉向到的網址是 192.168.0.13:81/static/a.html 第二種: location後沒有/ 轉發網站有/ #192.168.0.11---->server name # :80 ------------> port #/statc ---------->location #/a.html --------->proxy_pass location /static { proxy_pass http://192.168.0.13:81/; } 最後網址經過nginx轉向到的網址是 192.168.0.13:81/a.html 第三種: location後有/ 轉發網站沒有/ #192.168.0.11-->server name # :80 ------------> port #/statc/ ---------->location #a.html --------->proxy_pass location /static/ { proxy_pass http://192.168.0.13:81; } 最後網址經過nginx轉向到的網址是 192.168.0.13:81/static/a.html 第四種: location後有/ 轉發網站有/ #192.168.0.11-->server name # :80 ------------> port #/statc/ ---------->location(path1) #a.html --------->proxy_pass (path2) location /static/ { proxy_pass http://192.168.0.13:81/; } 最後網址經過nginx轉向到的網址是 192.168.0.13:81/a.html 總結: 從這四種我們可以的看出,當nginx裡面匹配時可以把埠後的引數分為path1+path2(其中我在上方標註的location屬於path1,proxy_pass屬於path2) 當proxy_pass 裡面是ip:port+/時nginx最後匹配的網址是 proxy_pass的內容加上path2 裡面是ip:port時nginx最後匹配的網址是 proxy_pass的內容加上path1+path2