This is similar to nginx url rewrite for reverse proxy , but I don't know how I should apply that answer to my situation.
I am trying rewrite URLs for a reverse proxy, so that /pathA/something
becomes /pathB/something
when Nginx makes the request to the upstream server.
location ~ /pathA(/|$) {
proxy_pass http://www.example.com;
proxy_redirect off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
rewrite ^/pathA(.*) /pathB$1;
}
I tried this, but I get an Nginx 404 page (and not the example.com 404 page).
I needed to add redirect (302) or permanent (301):
location ~ /pathA(/|$) {
proxy_pass http://www.example.com;
proxy_redirect off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
rewrite ^/pathA(.*) /pathB$1 permanent;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.