Nginx配置文件中l(wèi)ocation配置的多種場景
服務請求如下(示例):
- nginx服務: http://127.0.0.1:80
- 后臺服務:http://127.0.0.1:8088
- 測試url地址:http://127.0.0.1:8088/test/api/findAll
場景一、
nginx配置:
location /test/ {
proxy_pass http://127.0.0.1:8088/;
}
請求地址:http://127.0.0.1/test/api/findAll
實際上服務請求地址為:http://127.0.0.1:8088/api/findAll
規(guī)則:location最后有"/“,proxy_pass最后有”/" 結果為 proxy_pass + url中l(wèi)ocation最后一個斜線以后的部分
場景二、
nginx配置:
location /test {
proxy_pass http://127.0.0.1:8088/;
}
請求地址:http://127.0.0.1/test/api/findAll
實際上服務請求地址為:http://127.0.0.1:8088//api/findAll
規(guī)則:location最后無"/“,proxy_pass最后有”/" 結果為 proxy_pass + / + url中l(wèi)ocation最后一個斜線以后的部分
場景三、
nginx配置:
location /test/ {
proxy_pass http://127.0.0.1:8088;
}
請求地址:http://127.0.0.1/test/api/findAll
實際上服務請求地址為:http://127.0.0.1:8088/test/api/findAll
規(guī)則:location最后有"/“,proxy_pass最后無”/" 結果為 proxy_pass + location + url中l(wèi)ocation后面的部分(不包含第一個/)
場景四、
nginx配置:
location /test {
proxy_pass http://127.0.0.1:8088;
}
請求地址:http://127.0.0.1/test/api/findAll
實際上服務請求地址為:http://127.0.0.1:8088/test/api/findAll
規(guī)則:location最后無"/“,proxy_pass最后無”/" 結果為 proxy_pass + location + “/” + url中l(wèi)ocation后面的部分(不包含第一個/)
以下配置的規(guī)則可以參考上面的場景。
場景五、
nginx配置:
location /test/ {
proxy_pass http://127.0.0.1:8088/server/;
}
請求地址:http://127.0.0.1/test/api/findAll
實際上服務請求地址為:http://127.0.0.1:8088/server/api/findAll
場景六、
nginx配置:
location /test {
proxy_pass http://127.0.0.1:8088/server/;
}
請求地址:http://127.0.0.1/test/api/findAll
實際上服務請求地址為:http://127.0.0.1:8088/server//api/findAll
場景七、
nginx配置:
location /test {
proxy_pass http://127.0.0.1:8088/server/;
}
請求地址:http://127.0.0.1/test/api/findAll
實際上服務請求地址為:http://127.0.0.1:8088/serverapi/findAll
場景八、
nginx配置:
location /test {
proxy_pass http://127.0.0.1:8088/server;
}
請求地址:http://127.0.0.1/test/api/findAll
實際上服務請求地址為:http://127.0.0.1:8088/server/api/findAll
總結
以上就是nginx配置文件里location中“/”相關配置的筆記。
到此這篇關于Nginx配置文件中l(wèi)ocation配置的文章就介紹到這了,更多相關Nginx配置文件location配置內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
基于Nginx實現(xiàn)一個灰度上線系統(tǒng)的示例代碼
本文主要介紹了基于Nginx實現(xiàn)一個灰度上線系統(tǒng)的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-07-07
nginx反向代理https內(nèi)部定向到http報302的問題及解決
這篇文章主要介紹了nginx反向代理https內(nèi)部定向到http報302的問題及解決,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-12-12

