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)
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:
(insert into
/etc/sysctl.conf
for permanent)or add this line into
/etc/network/interfaces
, under inet6 interface definitionSource: http://pyro.eu.org/how-to/micro/nginx-cannot-assign-requested-address-ipv6.txt
I had similar symptoms, but a different configuration. The server runs Debian Wheezy with static IPv4 and IPv6 address configured.
At every boot, nginx failed to start:
Manually starting works fine and manual inspection also showed that the addresses and routes are set. Just setting the IPv6 address in
interfaces
(without the IPv4 address) worked. Removing the static IPv6 gateway also worked, but then a link-local gateway address is used. After further debugging, I found that the boot process would spit out:It turns out that an IPv6 address and gateway is automatically assigned by the router when the interface is brought up. To avoid this behavior, set
accept_ra 0
in theiface eth0 inet6
section. Theinet6
section has also to be moved before theinet
section or the default route will still point to the link-local address.On my Ubuntu 14.04 Hosts i just needed to move the IPv6 (inet6) entry BEFORE the IPv4 (inet) entry.
So this works: