Nginx配置文件中l(wèi)ocation配置的多種場景
服務(wù)請(qǐng)求如下(示例):
- nginx服務(wù): http://127.0.0.1:80
- 后臺(tái)服務(wù):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/; }
請(qǐng)求地址:http://127.0.0.1/test/api/findAll
實(shí)際上服務(wù)請(qǐng)求地址為:http://127.0.0.1:8088/api/findAll
規(guī)則:location最后有"/“,proxy_pass最后有”/" 結(jié)果為 proxy_pass + url中l(wèi)ocation最后一個(gè)斜線以后的部分
場景二、
nginx配置:
location /test { proxy_pass http://127.0.0.1:8088/; }
請(qǐng)求地址:http://127.0.0.1/test/api/findAll
實(shí)際上服務(wù)請(qǐng)求地址為:http://127.0.0.1:8088//api/findAll
規(guī)則:location最后無"/“,proxy_pass最后有”/" 結(jié)果為 proxy_pass + / + url中l(wèi)ocation最后一個(gè)斜線以后的部分
場景三、
nginx配置:
location /test/ { proxy_pass http://127.0.0.1:8088; }
請(qǐng)求地址:http://127.0.0.1/test/api/findAll
實(shí)際上服務(wù)請(qǐng)求地址為:http://127.0.0.1:8088/test/api/findAll
規(guī)則:location最后有"/“,proxy_pass最后無”/" 結(jié)果為 proxy_pass + location + url中l(wèi)ocation后面的部分(不包含第一個(gè)/)
場景四、
nginx配置:
location /test { proxy_pass http://127.0.0.1:8088; }
請(qǐng)求地址:http://127.0.0.1/test/api/findAll
實(shí)際上服務(wù)請(qǐng)求地址為:http://127.0.0.1:8088/test/api/findAll
規(guī)則:location最后無"/“,proxy_pass最后無”/" 結(jié)果為 proxy_pass + location + “/” + url中l(wèi)ocation后面的部分(不包含第一個(gè)/)
以下配置的規(guī)則可以參考上面的場景。
場景五、
nginx配置:
location /test/ { proxy_pass http://127.0.0.1:8088/server/; }
請(qǐng)求地址:http://127.0.0.1/test/api/findAll
實(shí)際上服務(wù)請(qǐng)求地址為:http://127.0.0.1:8088/server/api/findAll
場景六、
nginx配置:
location /test { proxy_pass http://127.0.0.1:8088/server/; }
請(qǐng)求地址:http://127.0.0.1/test/api/findAll
實(shí)際上服務(wù)請(qǐng)求地址為:http://127.0.0.1:8088/server//api/findAll
場景七、
nginx配置:
location /test { proxy_pass http://127.0.0.1:8088/server/; }
請(qǐng)求地址:http://127.0.0.1/test/api/findAll
實(shí)際上服務(wù)請(qǐng)求地址為:http://127.0.0.1:8088/serverapi/findAll
場景八、
nginx配置:
location /test { proxy_pass http://127.0.0.1:8088/server; }
請(qǐng)求地址:http://127.0.0.1/test/api/findAll
實(shí)際上服務(wù)請(qǐng)求地址為:http://127.0.0.1:8088/server/api/findAll
總結(jié)
以上就是nginx配置文件里location中“/”相關(guān)配置的筆記。
到此這篇關(guān)于Nginx配置文件中l(wèi)ocation配置的文章就介紹到這了,更多相關(guān)Nginx配置文件location配置內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
nginx實(shí)現(xiàn)多geoserver服務(wù)的負(fù)載均衡的示例代碼
本文主要介紹了nginx實(shí)現(xiàn)多geoserver服務(wù)的負(fù)載均衡的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05centos 7.0 使用Nginx部署flask應(yīng)用教程
這篇文章主要介紹了centos 7.0 使用Nginx部署flask應(yīng)用教程,需要的朋友可以參考下2017-12-12nginx利用ctx實(shí)現(xiàn)數(shù)據(jù)共享、修改上下文功能
這篇文章主要給大家介紹了關(guān)于nginx利用ctx實(shí)現(xiàn)數(shù)據(jù)共享、修改上下文功能的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-01-01