Nginx failed to start. Cannot assign requested address

nginxUbuntu

When I reboot my server (not nginx, the whole server), Nginx fails to start automatically. After I logged into the server, I can start nginx manually (service nginx start). It works. But if I restart again, I have to manually start Nginx. When checking the error.log for Nginx, I saw this error repeated several times :

2012/08/27 09:19:23 [emerg] 1066#0: bind() to [ipv6]:80 failed (99: Cannot assign requested address)

How can I fix this? What is this problem? (Im running an Ubuntu 12.04 server)

Best Answer

bind() to [ipv6]:80 failed (99: Cannot assign requested address)

It sounds like your IPv6 address has just been assigned to eth0, and still be in the tentative state, thus Nginx cannot establish a listen on that IP.

Either turn of DAD (Duplicate Address Detection) by running:

sysctl -w net.ipv6.conf.eth0.dad_transmits=0

(insert into /etc/sysctl.conf for permanent)

or add this line into /etc/network/interfaces, under inet6 interface definition

post-up while ip -6 addr show tentative | grep . > /dev/null ; do sleep 1 ; done

Source: http://pyro.eu.org/how-to/micro/nginx-cannot-assign-requested-address-ipv6.txt