3

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)

2
  • 1. ifconfig? 2. grep listen /path/to/nginx.conf?
    – quanta
    Aug 27, 2012 at 4:10
  • @quanta added the outputs :)
    – THpubs
    Aug 27, 2012 at 4:47

3 Answers 3

4

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

3
  • Thanks. What will be the best option out of the two? I also included the interfaces file on my server (please check the above question)
    – THpubs
    Aug 27, 2012 at 5:25
  • 1
    I think option 2 is better.
    – quanta
    Aug 27, 2012 at 5:34
  • Why is option 2 better?
    – Kalib Zen
    Dec 30, 2020 at 5:24
0

I had similar symptoms, but a different configuration. The server runs Debian Wheezy with static IPv4 and IPv6 address configured.

# /etc/network/interfaces
auto lo eth0
iface lo inet loopback

iface eth0 inet static
 address 192.0.2.3
 netmask 255.255.255.0
 gateway 192.0.2.1

iface eth0 inet6 static
 address 2001:db8::3
 netmask 64
 gateway 2001:db8::1        

At every boot, nginx failed to start:

bind() to [2001:db8::3]:80 failed (99: Cannot assign requested address)

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:

RTNETLINK answers: File exists
Failed to bring up eth0.

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 the iface eth0 inet6 section. The inet6 section has also to be moved before the inet section or the default route will still point to the link-local address.

0

On my Ubuntu 14.04 Hosts i just needed to move the IPv6 (inet6) entry BEFORE the IPv4 (inet) entry.

So this works:

auto eth0
iface eth0 inet6 static
    address fd57:c87d:f1ee:2::6
    netmask 64
    up /sbin/ip -6 route add fd57:c87d:f1ee::/48 via fe80::1 dev $IFACE

iface eth0 inet static
   address 10.0.3.29
   netmask 255.255.255.0
   gateway 10.0.3.1
   dns-nameserver 10.0.3.1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .