【标题】:Nginx location “/” 配置
服务访问
服务请求如下(示例):
- 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/server/api/findAll
总结
以上就是Nginx配置文件里location中“/”相关配置的笔记。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。