0

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).

Community
  • 1
  • 1
Paul Draper
  • 78,542
  • 46
  • 206
  • 285

1 Answers1

0

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;
}
Paul Draper
  • 78,542
  • 46
  • 206
  • 285