| Syntax: | proxy_redirect default proxy_redirect off proxy_redirect redirect replacement |
| Default: | default |
| Context: | http server location |
| Reference: | proxy_redirect |
This directive sets the text, which must be changed in response-header "Location" and "Refresh" in the response of the proxied server.
Let us suppose the proxied server returned line Location: http://localhost:8000/two/some/uri/.
The directive
proxy_redirect http://localhost:8000/two/ http://frontend/one/;
will rewrite this line in the form Location: http://frontend/one/some/uri/.
In the replaceable line it is possible not to indicate the name of the server:
proxy_redirect http://localhost:8000/two/ /;
then the basic name of server and port is set, if it is different from 80.
The change by default, given by the parameter "default", uses the parameters of directives location and proxy_pass.
Therefore two following configurations are equivalent:
location /one/ { proxy_pass http://upstream:port/two/; proxy_redirect default; } location /one/ { proxy_pass http://upstream:port/two/; proxy_redirect http://upstream:port/two/ /one/; }
In the replace line, it is possible to use some variables:
proxy_redirect http://localhost:8000/ http://$host:$server_port/;
This directive repeated some times:
proxy_redirect default; proxy_redirect http://localhost:8000/ /; proxy_redirect http://www.example.com/ /;
The parameter off forbids all proxy_redirect directives at this level:
proxy_redirect off; proxy_redirect default; proxy_redirect http://localhost:8000/ /; proxy_redirect http://www.example.com/ /;
With the help of this directive it is possible to add the name of host for relative redirect, issued by the proxied server:
proxy_redirect / /;