小白请教一个 nginx 的配置问题
- 0次
- 2021-05-19 22:55:46
- idczone
一个请求 /api1/auth/loginout/
我在接收到抗投诉服务器 /api1/auth/loginout 的请求后要把请求首地址 api1 转发到另一个服务器的 auth/logunout/接口要如何去写
这么写的话转发过去 请求接口依然是 /api1/auth/loginout
location /api1 {
proxy_pass http://192.168.0.1:5000/;
}
location /api1/auth/loginout {
proxy_pass http://ip/auth/loginout;
}
增加一个'/':
location /api1/ {
proxy_pass http://192.168.0.1:5000/;
}
或者:
location /api1/auth/ {
proxy_pass http://192.168.0.1:5000/auth/;
}
等等。
写法有很多,最好查一下相关文档,全面理解一下。
2 楼正解
location /api1/ { <-------------注意结尾这个斜杠,必须要有
proxy_pass http://192.168.0.1:5000/;
}
是只有 /api1/auth/loginout/这个请求吗,还是 /api1 下的所有请求?
可以看一下 nginx 的 rewrite 模块,我觉得是跟你需求比较接近的一种简单的实现方式