日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

Nginx配置文件中location配置的多種場景_nginx

作者:SmallCat0912 ? 更新時間: 2022-11-05 編程語言

服務請求如下(示例):

  • 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

規則:location最后有"/“,proxy_pass最后有”/" 結果為 proxy_pass + url中location最后一個斜線以后的部分

場景二、

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

規則:location最后無"/“,proxy_pass最后有”/" 結果為 proxy_pass + / + url中location最后一個斜線以后的部分

場景三、

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

規則:location最后有"/“,proxy_pass最后無”/" 結果為 proxy_pass + location + url中location后面的部分(不包含第一個/)

場景四、

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

規則:location最后無"/“,proxy_pass最后無”/" 結果為 proxy_pass + location + “/” + url中location后面的部分(不包含第一個/)

以下配置的規則可以參考上面的場景。

場景五、

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中“/”相關配置的筆記。

原文鏈接:https://blog.csdn.net/SmallCat0912/article/details/125391486

欄目分類
最近更新