2022
我们一起努力

Nginx配置文件中location配置的多种场景(nginx配置文件中local什么意思)

内容介绍
  • 服务请求如下(示例):
  • 场景一、
  • 场景二、
  • 场景三、
  • 场景四、
  • 场景五、
  • 场景六、
  • 场景七、
  • 场景八、
  • 总结

服务请求如下(示例):

  • 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中“/”相关配置的笔记。

到此这篇关于Nginx配置文件中location配置的文章就介绍到这了,更多相关Nginx配置文件location配置内容请搜索站长源码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持站长源码网!

本文从互联网转载,来源地址:www.downzz.com/fuwuqi/247493.html,原作者保留一切权利,若侵权或引用不当,请联系茶猫云(cmy.cn)删除。【茶猫云,优质云服务器提供商】

赞(0)
文章名称:《Nginx配置文件中location配置的多种场景(nginx配置文件中local什么意思)》
文章链接:https://www.fzvps.com/39836.html
本站文章来源于互联网,如有侵权,请联系管理删除,本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。
图片版权归属各自创作者所有,图片水印出于防止被无耻之徒盗取劳动成果的目的。

评论 抢沙发

评论前必须登录!