The proxy_redirect
directive in Nginx allows you to change the Location
and Refresh
headers in the response of the server. This can be useful if you are using Nginx as a reverse proxy and want to adjust the location of the resource being requested or redirect the client to a different URL.
To use the proxy_redirect
directive, you can include it in the location
block of your Nginx configuration file. Here's an example of how to use proxy_redirect
to change the Location
header in the response of the server:
location / { proxy_pass http://upstream; proxy_redirect default; }
This will pass all requests to the /
location to the upstream
server and set the Location
header in the response to the default value.
You can also use the proxy_redirect
directive to specify a custom value for the Location
header. For example:
location / { proxy_pass http://upstream; proxy_redirect http://upstream https://example.com; }
This will set the Location
header in the response to https://example.com
if the original value of the header is http://upstream
.
To use the proxy_redirect
directive to change the Refresh
header in the response of the server, you can use the refresh
parameter. For example:
location / { proxy_pass http://upstream; proxy_redirect refresh; }
This will set the Refresh
header in the response to the default value.
It's important to note that the proxy_redirect
directive is just one of the many directives available in Nginx for configuring reverse proxy behavior. Consult the Nginx documentation and online resources for more information on how to use the proxy_redirect
directive and other directives to configure reverse proxy behavior in Nginx.