Nginx proxy_redirect: Change response-header Location and Refresh in the response of the server

by on June 27, 2012 · 1 comment· LAST UPDATED June 27, 2012


How do I replace upstream "Location:" http/301 response-header with "Location:" in the response of the proxied server using nginx?

Nginx provides proxy_redirect directive which can be used in http, server, or location context. The syntax is:

proxy_redirect redirect replacement

In this example, the proxied server (upstream Apache or Lighttpd) returned line Location: The following directive in nginx.conf:


will rewrite this line in the form Location: Save and close the file. Reload the nginx server
# service nginx reload
# /usr/local/nginx/sbin/nginx -s reload
You can verify this with the curl command:
$ curl -I
$ curl

In the replace line, it is possible to use variables as follows:

proxy_redirect    http://$host:$server_port/;

The parameter off forbids all proxy_redirect directives:

proxy_redirect off;
Tweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?

{ 1 comment… read it below or add one }

1 ceooph March 12, 2013 at 11:32 am

Thanks for ALL your articles, about nginx and [lu]nix ;-)
I’ve a question about nginx. And I hope you can answer it ;-)
We do reverse proxy to access from internet some documentation filtering by ip address. These documentations are hosted on commercials portals.
For 1 base we are often redirect between 2 or 3 (sometimes 6) servers.
And we have access to more than 50 bases !
Do you know if with nginx it’s possible to do proxy_pass (and proxy_redirect) to these server one 1 virtual name ?
I try it with different location for each server but it’s doesn’t work.

Thanks in advance for your help. You can contact me at
And continue your blog ! When I search documentation about linux and I find an article on your site, I know that I’ll have to response ;-)


Leave a Comment

Tagged as: , , , , , , , , , ,

Previous Faq:

Next Faq: