nginx howto correct the path from a back-end server redirect response under a virtual directory
- by noname
The following was my deployed servers:
client ------ nginx proxy(example.com) ------ back-end server(192.168.1.20)
The nginx proxy's external URL was configured under a virtual directory http://example.com/demo/
The back-end server was configure to http://192.168.1.20:8080/
the following was part of the nginx configure file:
location /demo {
proxy_pass http://192.168.1.20:8080/;
proxy_redirect default;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
When the back-end server send a redirect response (HTTP CODE 302) with LOCATION head field "http://192.168.1.20/subdir/", the nginx map this LOCATION header field to "http://example.com/subdir/", not the disired "http://example.com/demo/subdir/"