Hello agentzh
As outlined in the documentation at http://wiki.nginx.org/HttpHeadersMoreModule#more_set_headers, the nginx in proxy mode can change the Location header in response to any arbitrary string i.e.
more_set_headers 'Location:string'
What if in proxy mode, we want to set the Location header such that only the host is changed i.e.
Let's say nginx proxy is host1.com and the origin server is host2.com
The origin server sends a 302 redirect with Location:host2.com/page1.html
We want to send the client Location:host1.com/page1.html
I cannot hardcode page1.html part in more_set_headers as
' Location:host1.com/page1.html'. Since the origin server can send a Location for page1.html or page2.html. Ideally this should come from an nginx variable i.e. something similar to
'Location:host1.com/$resourceloc where $resourceloc is the variable which can be page1.html= or page2.html
Such a variable is not defined in nginx as far as I can see. Is there any alternative way to do it.
PS: on the request side, there is a similar problem but I was able to solve it for example in referer header
by specifying
more_set_input_headers 'Referer:Host2.com$request_uri'.