nginx配置proxy_pass中url末尾帶/與不帶/的區(qū)別詳解
nginx配置proxy_pass時url末尾帶“/”與不帶“/”的區(qū)別如下:
注意:當location為正則表達式匹配模式時,proxy_pass中的url末尾是不允許有"/"的,因此正則表達式匹配模式不在討論范圍內。
proxy_pass配置中url末尾帶/時,nginx轉發(fā)時,會將原uri去除location匹配表達式后的內容拼接在proxy_pass中url之后。
測試地址:http://192.168.171.129/test/tes.jsp
場景一:
location ^~ /test/ { proxy_pass http://192.168.171.129:8080/server/; }
代理后實際訪問地址:http://192.168.171.129:8080/server/tes.jsp
場景二:
location ^~ /test { proxy_pass http://192.168.171.129:8080/server/; }
代理后實際訪問地址:http://192.168.171.129:8080/server//tes.jsp
場景三:
location ^~ /test/ { proxy_pass http://192.168.171.129:8080/; }
代理后實際訪問地址:http://192.168.171.129:8080/tes.jsp
場景四:
location ^~ /test { proxy_pass http://192.168.171.129:8080/; }
代理后實際訪問地址:http://192.168.171.129:8080//tes.jsp
proxy_pass配置中url末尾不帶/時,如url中不包含path,則直接將原uri拼接在proxy_pass中url之后;如url中包含path,則將原uri去除location匹配表達式后的內容拼接在proxy_pass中的url之后。
測試地址:http://192.168.171.129/test/tes.jsp
場景一:
location ^~ /test/{ proxy_pass http://192.168.171.129:8080/server; }
代理后實際訪問地址:http://192.168.171.129:8080/servertes.jsp
場景二:
location ^~ /test { proxy_pass http://192.168.171.129:8080/server; }
代理后實際訪問地址:http://192.168.171.129:8080/server/tes.jsp
場景三:
location ^~ /test/ { proxy_pass http://192.168.171.129:8080; }
代理后實際訪問地址:http://192.168.171.129:8080/test/tes.jsp
場景四:
location ^~ /test { proxy_pass http://192.168.171.129:8080; }
代理后實際訪問地址:http://192.168.171.129:8080/test/tes.jsp
到此這篇關于nginx配置proxy_pass中url末尾帶/與不帶/的區(qū)別詳解的文章就介紹到這了,更多相關nginx proxy_pass url末尾內容請搜索本站以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持本站!
版權聲明:本站文章來源標注為YINGSOO的內容版權均為本站所有,歡迎引用、轉載,請保持原文完整并注明來源及原文鏈接。禁止復制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務器上建立鏡像,否則將依法追究法律責任。本站部分內容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學習參考,不代表本站立場,如有內容涉嫌侵權,請聯(lián)系alex-e#qq.com處理。