Problem with a reverse proxy and trailing slash redirects

Andre Nathan andre at digirati.com.br
Fri Aug 15 17:33:39 UTC 2014


Hello

We have a service for our customers that allows them to test their site
before they point their DNS to our servers. It works like this: we
configure their websites in our backend servers as usual, and we create
an entry in a zone we own. Say the customer's site is www.foo.com; we
give him a temporary address at foo.tmpzone.com where he can try our
services without changing his DNS records.

This is done by configuring foo.tmpzone.com in Nginx, which then
redirects to the backend server:

server {
  listen      1.2.3.4:80;
  server_name foo.tmpzone.com;

  location / {
    proxy_pass http://4.3.2.1;
    proxy_redirect http://4.3.2.1/ http://$host/;
    proxy_set_header Host www.foo.com;
  }
}

The problem with this setup is that if one tries to access, say,
foo.tmpzone.com/blah, Nginx will issue a 301 redirect adding a trailing
slash, but the Location will be set to "www.foo.com/blah/". This seems
to be due to the proxy_set_header directive, which is needed for the
backend server to find the appropriate virtual host.

Is there any way to override this behavior and have Nginx redirect to
foo.tmpzone.com/blah/ instead? I tried turning on the
server_name_in_redirect directive, but it didn't work.

Thanks in advance,
Andre


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 474 bytes
Desc: not available
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20140815/0a773616/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: OpenPGP digital signature
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20140815/0a773616/attachment-0001.bin>


More information about the nginx mailing list