Intercepting backend 301/302 redirects (proxy_pass) and rewriting to another location block possible?

You could use proxy_redirect directive:

http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_redirect

Nginx will still return 301/302 to the client but proxy_redirect will modify Location header and the client should make a new request to the URL given in the Location header.

Something like this should make the subsequent request back to nginx:

proxy_redirect http://upstream:port/ http://$http_host/;

Leave a Comment