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

Refers to:

  • Plesk 12.5 for Linux
  • Plesk Onyx for Linux

Created:

2016-11-16 12:44:36 UTC

Modified:

2017-01-25 05:25:53 UTC

2

Was this article helpful?


Have more questions?

Submit a request

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

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 gets 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. Make sure that network interfaces are enabled on system boot (use one of the following commands depending on OS used - Red Hat based or Debian based):  
    # grep "ONBOOT" /etc/sysconfig/network-scripts/ifcfg-eth0
    # grep auto /etc/network/interfaces
  2. Back up nginx startup script /etc/systemd/system/multi-user.target.wants/nginx.service

  3. 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 and replace:

     

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

with:

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

     

     4. Reboot the server

 Note: If steps above was not helped on CentOS 7, then follow this article

 

 

Have more questions? Submit a request

12 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.

Please sign in to leave a comment.