Varnish + Nginx redirect without port

If you have Varnish running on port 80, Nginx has to run on a different port behind it. Varnish accepts requests on port 80 and either serves up the cached content or passes it to the registered backend (Nginx) running on, say, port 801.
Things get a bit funky when your Nginx configuration forces a trailing slash redirect and you may end up seeing a request for example.com/some-path being redirected to example.com:801/some-path/
Obviously your port 801 won't be accessible to the public (you'll have a firewall rule for this, won't you?) so requests will fail/time-out.

Handily, Nginx has an inbuilt solution for this called port_in_redirect - add this to the relevant location (or http,server context), set it to 'off', test (-t) and reload nginx and the web server will send the Location header back without the port in the URL.

You may hit this issue when maintaining canonical urls for your resources (e.g ensuring a trailing slash on directory paths). The less duplicate URLs you have, the less 'thin' your content becomes, which can in turn have a positive effect on your site's search engine ranking performance.

Post your comment

Comments

No one has commented on this page yet.

RSS feed for comments on this page | RSS feed for all comments