大家好,工作中遇到一个棘手的小问题,由于时间比较急,没查到详细的信息,所以想请教一下大家,谢谢啦
如何用 nginx 将 IP 地址 /api/ 代理到 IP 地址 / ? 例子:IP 地址 /api/user/userlist 代理到 IP 地址 /user/userlist
大家好,工作中遇到一个棘手的小问题,由于时间比较急,没查到详细的信息,所以想请教一下大家,谢谢啦
如何用 nginx 将 IP 地址 /api/ 代理到 IP 地址 / ? 例子:IP 地址 /api/user/userlist 代理到 IP 地址 /user/userlist
|
lowerMay 22, 2020
1
好像要用 rewrite
|
|
fcxjluoMay 22, 2020
2
location /api/user/userlist {
rewrite /api/user/userlist /user/userlist break; proxy_pass http://ip; } |
|
fcxjluoMay 22, 2020
3
location /api/user/userlist {
rewrite /api/(.*) /$1 break; proxy_pass http://ip; } |
|
ragnaroksMay 22, 2020
4
google: proxy_pass
|
|
foamMay 22, 2020 via Android
5
|
|
6
|
|
mmnsghgnMay 22, 2020
8
https://xuexb.github.io/learn-nginx/example/proxy_pass.html
摘抄: // 访问: /api/ 后端: / // 访问: /api/xx 后端: /xx // 访问: /api/xx?aa 后端: /xx?aa // 访问: /api-xx?aa 未匹配 location /api/ { proxy_pass http://node:8080/; } |
|
hstvMay 22, 2020
9
@zhengjian 这个正解。
location /api/ { proxy_pass http://ip; #会指向 http://ip/api/user/userlist proxy_pass http://ip/; #会指向 http://ip/user/userlist } |
|
10
|