NGINX -重写基础 url 保留 url 的一部分

NGINX -Rewrite base url keeping part of url

我通过 nginx 为我的 api 调用设置了几个代理。例如

http://localhost:5000/application/api1/get/user 将被重定向到

https://example.com/application/api1/get/user

location ~* "^/api1" {
   proxy_pass https://example.com;
}

现在我必须重定向一些电话:

http://localhost:5000/application/api2/get/data to https://example.com/api2/get/data

注意:我这次不需要申请...

我已经试过了:

location ~* "^/api2" {
   rewrite ^/application/(.*) /
   proxy_pass https://example.com;
}

但是好像不行:(

你可以试试这个...

location /application/api2/ {
   include proxy_params;
   proxy_set_header X-Forwarded-Proto https;
   proxy_pass https://example.com/api2/;
}

我们也可以进一步讨论...