I am trying to do a permanent redirect from a subpath location on a original server (https://my-server1.com/api/old/subpath
) to the root of an external host while keeping the subpath (https://my-server2.com/subpath
), the HTTP method (generally the request are POST requests) and the headers (the headers include authentication data).
I have been trying the following:
1.
location ^/api/old(.*)$ {
rewrite $scheme://my-server2.com$1 permanent;
}
…but I get a 404 when doing the POST request
2.
location /api/old {
rewrite ^/api/old(.*)$ $scheme://my-server2.com$1 permanent;
5
…but I get a 405 when doing the POST request, I believe because the POST request is changed into a GET
3.
location ~ ^/api/old(.*)$ {
return 308 $scheme://my-server2.com$1;
}
…but I get a 403 when doing the POST request, I believe the method is ok, but the auth headers is not forwarded
4.
location ~ ^/api/old(.*)$ {
proxy_pass $scheme://my-server2.com$1;
}
…but I get a 502 (not idea why exactly).
Which one is the right method to do so, and what am I missing here?