Nginx unable to bind, address already in use.

Just now, I added a vhost to my nginx configuration on a machine I administer, restart nginx, and am baffled about the following error message:

Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

This is weird… nginx was running just fine up until now, and suddenly won’t start. I tried checking if it was still running, which it wasn’t, tried looking at netstat to see if any other processes are bound to that port.

# netstat -platune

This is weird. Let’s see if I can bind to port 80 myself with ‘nc’.

# nc -v -l 80

It can bind to the port just fine, let’s see if I can connect.

# telnet example.com 80
Trying 203.0.113.128...
telnet: connect to address 203.0.113.128: Connection refused
Trying 2001:db8:c0ld:c0:ff:ee::1...
telnet: connect to address 2001:db8:c0ld:c0:ff:ee::1: No route to host
telnet: Unable to connect to remote host

This is weird, the port is open, but it won’t connect. This must be my firewall interfering. After stopping the firewall, the same behaviour persisted.

After trying out some of my google skills, I stumble upon the following post on StackOverflow: http://stackoverflow.com/a/15101745/359664

It seems that because of IPv6, the port is unable to bind.

After rewriting my nginx vhosts’s to the following format, nginx is willing to start and everything is online again.

This makes me wonder, what is happening with my IPv6 traffic?

My IPv4 address is assigned through a DHCP server, and my IPv6 is assigned by a similar concept, namely SLAAC.

I can ping the outside world, and I can ping the machine from the outside.

# ping ipv6.google.com

Let’s check the same things on IPv6.

# ip6tables-save

This looks fine to me… oh wait… Port 80 is not allowed in here… I must have only allowed it in the IPv4 configuration.

After configuring the IPv6 firewall correctly (which you should always do, don’t forget about it is a lesson ;-)

I’m still baffled why the IPv6 isn’t working…