Nginx无法启动。 无法分配请求的地址?

当我重新启动我的服务器(而不是nginx,整个服务器),Nginx无法自动启动。 login服务器后,我可以手动启动nginx(服务nginx启动)。 有用。 但是,如果我再次重新启动,我必须手动启动Nginx。 在检查Nginx的error.log时,我看到这个错误重复了几次:

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

我怎样才能解决这个问题? 这是什么问题? (我正在运行Ubuntu 12.04服务器)

绑定()到[ipv6]:80失败(99:无法分配请求的地址)

听起来你的IPv6地址刚刚被分配给了eth0,而且还处于暂时的状态 ,所以Nginx不能build立一个监听这个IP。

通过运行以下任何一种方法都可以打开DAD( 重复地址检测 ):

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

(插入到/etc/sysctl.conf永久)

或者将这行添加到/etc/network/interfaces下,在inet6接口定义下

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

资料来源: http : //pyro.eu.org/how-to/micro/nginx-cannot-assign-requested-address-ipv6.txt

我有类似的症状,但有不同的configuration。 服务器运行configuration了静态IPv4和IPv6地址的Debian Wheezy。

 # /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 

在每次启动时,nginx启动失败:

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

手动启动工作正常,手动检查也显示地址和路由已设置。 只需在interfaces (不包括IPv4地址)中设置IPv6地址即可。 除去静态IPv6网关也起作用,但是使用链路本地网关地址。 进一步debugging之后,我发现启动过程会吐出来:

 RTNETLINK answers: File exists Failed to bring up eth0. 

事实certificate,在接口启动时,路由器会自动分配IPv6地址和网关。 为了避免这种情况, accept_ra 0iface eth0 inet6部分设置accept_ra 0inet6部分还必须在inet部分之前移动,否则默认路由仍然会指向链接本地地址。

在我的Ubuntu 14.04主机上,我只需要在IPv4(inet)条目之前移动IPv6(inet6)条目。

所以这个工作:

 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