当前位置: 首页> 汽车> 新车 > 公司企业建站报价_b站到底是哪个网站_北大青鸟软件开发培训学费多少_郑州网络营销公司排名

公司企业建站报价_b站到底是哪个网站_北大青鸟软件开发培训学费多少_郑州网络营销公司排名

时间:2025/7/11 7:56:55来源:https://blog.csdn.net/u013571994/article/details/143262289 浏览次数: 0次
公司企业建站报价_b站到底是哪个网站_北大青鸟软件开发培训学费多少_郑州网络营销公司排名

1、基本规则

假如后端实际地址为:

http://127.0.0.1:8080/api/user/getById?id=123

则:

1)通过nginx转发,使用http://127.0.0.1/api/user/getById?id=123访问

server {listen       80;server_name  127.0.0.1;location /api/ {proxy_pass http://127.0.0.1:8080;}}

通过原有地址直接准发非常简单。

2)通过nginx转发,使用http://127.0.0.1/test/api/user/getById?id=123访问

server {listen       80;server_name  127.0.0.1;location /test/ {proxy_pass http://127.0.0.1:8080/;}}

这里相当于对请求添加了前缀,但在转发的过程中是没有前缀的,故需要去掉。关键点就是地址后面的 "/"

2.关于斜杆"/"的案例对比

以服务地址http://127.0.0.1:8080/api/user/getById进行说明,访问地址是http://127.0.0.1/api/user/getById。location后斜杆与proxy_pass后斜杆问题如下:

1)location、proxy_pass都不加斜杠

location /api {proxy_pass http://127.0.0.1:8080;
}

实际代理地址:http://127.0.0.1:8080/api/user/getById。正确的

2)location加斜杠,proxy_pass不加斜杠

location /api/ {proxy_pass http://127.0.0.1:8080;
}

实际代理地址:http://127.0.0.1:8080/api/user/getById。正确的

3)location不加斜杠,proxy_pass加斜杠

location /api {proxy_pass http://127.0.0.1:8080/;
}

实际代理地址:http://127.0.0.1:8080//user/getById。错误的,也出现了双斜杠

4)location、proxy_pass都加斜杠

location /api/ {proxy_pass http://127.0.0.1:8080/;
}

实际代理地址:http://127.0.0.1:8080/user/getById

5)location不加斜杠,proxy_pass加"api"

location /api {proxy_pass http://127.0.0.1:8080/api;
}

实际代理地址:http://127.0.0.1:8080/api/user/getById。正确的

6)location加斜杠,proxy_pass加"api"

location /api/ {proxy_pass http://127.0.0.1:8080/api;
}

实际代理地址:http://127.0.0.1:8080/apiuser/getById。错误的,少了一个斜杆

7)location不加斜杠,proxy_pass加"api/"

location /api {proxy_pass http://127.0.0.1:8080/api/;

实际代理地址:http://127.0.0.1:8080/api//user/getById。这种情况会出现双斜杠问题,后端在认证请求时会校验失败。

8)location加斜杠,proxy_pass加"api/"

location /api/ {proxy_pass http://127.0.0.1:8080/api/;
}

实际代理地址:http://127.0.0.1:8080/api/user/getById。正确的

可以看出,两者加不加斜杆的区别还是很大的,不同的场景使用不同的配置即可。简单的,要么都不加,这样转发的地址是对应的。

关键字:公司企业建站报价_b站到底是哪个网站_北大青鸟软件开发培训学费多少_郑州网络营销公司排名

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: