Nginx does not start automatically after reboot: 99: Cannot assign requested address

Created:

2016-11-16 12:44:36 UTC

Modified:

2017-08-19 05:43:31 UTC

18

Was this article helpful?


Have more questions?

Submit a request

Nginx does not start automatically after reboot: 99: Cannot assign requested address

Applicable to:

  • Plesk 12.5 for Linux
  • Plesk Onyx for Linux

Symptoms

After server reboot nginx does not get started:

# systemctl --failed
UNIT LOAD ACTIVE SUB DESCRIPTION
● nginx.service loaded failed failed Startup script for nginx service

OS with systemd is installed (Debian 8, CentOS 7 and etc.).

In /var/log/nginx/error.log the following messages can be found:

[emerg] 1140#0: bind() to [203.0.113.2]:80 failed (99: Cannot assign requested address)

In journalctl the following entries can be found:

# journalctl -u network.service -u network.target -u nginx.service -b
nginx[352]: nginx: [emerg] bind() to 203.0.113.2:80 failed (99: Cannot assign requested address)
systemd[1]: Failed to start Startup script for nginx service.
systemd[1]: Unit nginx.service entered failed state.
network[268]: Bringing up interface eth0:
dhclient[665]: DHCPREQUEST on eth0 to 255.255.255.255 port 67 (xid=0x4b684081)
dhclient[665]: DHCPACK from 203.0.113.2 (xid=0x4b684081)
network[268]: [ OK ]

However, nginx can be started manually without any issues:

# systemctl start nginx.service

Cause

Delay in assigning of IP address to a network interface. For example, because of delayed response from DHCP server.

Resolution

1. Connect to the server using SSH.

2. Make sure that network interfaces are enabled on system boot:

for Red Hat based OS:

# grep -r "ONBOOT" /etc/sysconfig/network-scripts/ifcfg-*
/etc/sysconfig/network-scripts/ifcfg-lo:ONBOOT=yes
/etc/sysconfig/network-scripts/ifcfg-venet0:ONBOOT=yes
/etc/sysconfig/network-scripts/ifcfg-venet0:0:ONBOOT=yes

For Debian based OS:

# grep auto /etc/network/interfaces
# This configuration file is auto-generated.
auto lo
auto venet0
auto venet0:0

3. Back up nginx startup script /etc/systemd/system/multi-user.target.wants/nginx.service:

# cp /etc/systemd/system/multi-user.target.wants/nginx.service /etc/systemd/system/multi-user.target.wants/nginx.service_backup

4. Configure nginx startup script to be executed after network is up and all IP addresses are assigned: open file /etc/systemd/system/multi-user.target.wants/nginx.service using any text editor on Linux (for example, vim or nano) and replace:

After=network.target remote-fs.target nss-lookup.target

with:

After=network-online.target remote-fs.target nss-lookup.target     

5. Reboot the server

If steps above were not helpful on CentOS 7, follow:

Nginx service fails to start on CentOS 7 boot with Plesk 12.0: 99: Cannot assign requested address

Have more questions? Submit a request

15 Comments

  • 0
    Avatar
    Aniello Martuscelli

    same problem here on ubuntu 16.04 with onyx

    how can solve there is any patch?

    into logs i've found

    gen 17 02:52:51 host-01 nginx[1977]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

    gen 17 02:52:51 host-01 nginx[1977]: nginx: [emerg] bind() to [2001:41d0:1000:2264::]:80 failed (99: Cannot assign requested address)

    gen 17 02:52:51 host-01 nginx[1977]: nginx: configuration file /etc/nginx/nginx.conf test failed

  • 0
    Avatar
    Lev Iurev

    Hi @Aniello, did you try to use this article?

  • 0
    Avatar
    Benjamin Hodgetts

    If this is a known issue and the fix is known, why hasn't the fix been implemented into the package itself? (i.e. that network.target should be network-online.target).

  • 0
    Avatar
    Lev Iurev

    Hi @Benjamin, because Plesk uses system package from system repo.

  • 0
    Avatar
    Benjamin Hodgetts

    Are you sure? Nginx is provided by "sw-nginx-*.rpm" which is your own build (hence the "sw") from your own repos.

  • 0
    Avatar
    Jens Wiesser

    @Aniello, i got the same Error. 

    # grep "ONBOOT" /etc/sysconfig/network-scripts/ifcfg-eth0

    This ist not working on Ubuntu. This is for CentOS. Any advice to solve this Problem?

    Jan 20 12:03:42 host-xyz systemd[1]: Reached target Network.
    Jan 20 12:03:47 host-xyz systemd[1]: Starting Startup script for nginx service...
    Jan 20 12:03:50 host-xyz nginx[1160]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    Jan 20 12:03:50 host-xyz nginx[1160]: nginx: [emerg] bind() to xxx.xxx.xxx.xxx:80 failed (99: Cannot assign requested address)
    Jan 20 12:03:50 host-xyz nginx[1160]: nginx: configuration file /etc/nginx/nginx.conf test failed
    Jan 20 12:03:50 host-xyz systemd[1]: nginx.service: Control process exited, code=exited status=1
    Jan 20 12:03:50 host-xyz systemd[1]: Failed to start Startup script for nginx service.
    Jan 20 12:03:50 host-xyz systemd[1]: nginx.service: Unit entered failed state.
    Jan 20 12:03:50 host-xyz systemd[1]: nginx.service: Failed with result 'exit-code'.

    Edited by Jens Wiesser
  • 0
    Avatar
    Alexander Tsmokalyuk

    @Aniello Thank you for the question. The solution is not implemented in a patch because in the environments where there is no any delay in putting network interfaces up it would make unnecessary delays of OS boot process (i.e. of nginx service).

    Edited by Alexander Tsmokalyuk
  • 0
    Avatar
    Alexander Tsmokalyuk

    @Benjamin yes, the package is built by us.

  • 0
    Avatar
    Aniello Martuscelli

    @Lev Iurev

    I've changed this

    After=network-online.target remote-fs.target nss-lookup.target

    nothing changed, after reboot I should give

    service nginx restart

  • 0
    Avatar
    Vitaly Zhidkov

    @Aniello, this should be checked deeper. Please contact you hosting provider and ask them to check it on server level. If it will be necessary they will submit a support ticket for us.

  • 0
    Avatar
    Aniello Martuscelli

    @Vitaly, I've selfmanaged dedicated from OVH

    They said me that not handle software problems. I've tried to open support ticket on Your site, but my license is not accepted because brought from OVH

    However I've another dedicated server (same hardware 6core, 128gbram, 2xSSD NVMe, ubuntu 16.04) with ISPConfig, but i've this problem only with Plesk Onyx

    Edited by Aniello Martuscelli
  • 0
    Avatar
    Lev Iurev

    @Aniello, if you've bought Plesk with license from OVH, they should support your issue with Plesk.

  • 0
    Avatar
    Benjamin Hodgetts

    "The solution is not implemented in a patch because in the environments where there is no any delay in putting network interfaces up it would make unnecessary delays of OS boot process"

    Surely if there's no delay in putting network interfaces up then network-online wouldn't cause a delay because it's already up, no?

  • 0
    Avatar
    Vitaly Zhidkov

    @Benjamin, in case there is no delay in IP assign there would be also no delays in OS boot process.

  • 0
    Avatar
    Paolo Bertinetti

    I had this morning the same problem on Plesk Onyx 17.0.17 #29/CentOS Linux 7.3.1611 (Core). This solution was very useful!

    Thanks

Please sign in to leave a comment.