Tay Ray Chuan home archive

squelching port numbers in nginx redirects

Wed, 2 Jun 2010 00:58:21 +0800 | Filed under nginx, webfaction

I'm running a nginx installation on webfaction, and it's long bothered me that URL rewrites/redirects in nginx included the port number in the resulting host.

For example, if you had this piece of config

server {
	listen	1001;
	server_name	foo.com;

	location = / {
		rewrite ^.*$ /under_construction redirect;

a hit on http://foo.com would lead to a 301 to http://foo.com:1001/under_construction - ugh.

Today, I decided to re-read the docs, and stumbled upon port_in_redirect - exactly what I was looking for. Nice. While there, I happened to spot a fairly trivial mistake and had a nice laugh - and fixed it, of course.

blog comments powered by Disqus