1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > Nginx配置文件中location配置

Nginx配置文件中location配置

时间:2020-02-14 01:19:22

相关推荐

Nginx配置文件中location配置

【标题】: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中“/”相关配置的笔记。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。