Applicable to:
- Plesk Onyx for Linux
- Plesk Obsidian 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 - Domains are not working.
-
OS with
systemd
is installed (Debian 8, CentOS 7 and etc.). -
In
/var/log/nginx/error.log
the following messages can be found:CONFIG_TEXT: [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
-
Connect to the server using SSH.
-
Make sure that network interfaces are enabled on system boot:
-
for RHEL, CentOS, CloudLinux:
# 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 and Ubuntu:
# grep auto /etc/network/interfaces
# This configuration file is auto-generated.
auto lo
auto venet0
auto venet0:0
-
-
Back up the nginx startup script
/etc/systemd/system/multi-user.target.wants/nginx.service:
# cp /etc/systemd/system/multi-user.target.wants/nginx.service{,.bk}
-
Make sure that the package
systemd-networkd
is installed on the server. Install it if it is not installed:-
for RHEL, CentOS, CloudLinux:
# yum install systemd-networkd
-
for Debian and Ubuntu:
Should be installed by default.The service will ensure that network interfaces are up and have IP addresses bound. For additional details, refer to http://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/
-
-
If Plesk 17.5 or older is used, proceed as follows to create the file
/etc/systemd/system/nginx.service.d/override.conf
with an nginx startup parameter to be executed only after the network is up and all IP addresses are assigned:-
Run the following command. It will open the default text editor on the server:
# systemctl edit nginx.service
Add the following line, save and exit the file:
CONFIG_TEXT: After=network-online.target remote-fs.target nss-lookup.target
-
- Reboot the server:
# reboot
If it does not help, additional action is required:
-
For SystemD add the following line in
[Service]
section in/etc/systemd/system/multi-user.target.wants/nginx.service
file:CONFIG_TEXT: ExecStartPre=/bin/sleep 10
Note: Increase timeout if needed.
-
For OS without SystemD, edit
/etc/init.d/nginx
adding sleep command to the start, so it should look like:# grep -i "start()" /etc/init.d/nginx
start() { sleep 20 -
Reboot the server:
# reboot
Comments
25 comments
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
Hi @Aniello, did you try to use this article?
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).
Hi @Benjamin, because Plesk uses system package from system repo.
Are you sure? Nginx is provided by "sw-nginx-*.rpm" which is your own build (hence the "sw") from your own repos.
@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'.
@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).
@Benjamin yes, the package is built by us.
@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
@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.
@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
@Aniello, if you've bought Plesk with license from OVH, they should support your issue with Plesk.
"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?
@Benjamin, in case there is no delay in IP assign there would be also no delays in OS boot process.
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
This solution is NOT working for me on Plesk Onyx v17.5.3/CentOS Linux 7.4.1708. Can anyone help me?
@Klemen, letm me know the error from /var/log/nginx/error.log and journalctl
Than you @Lev, here are errors:
nginx log file:
10:07:21 [emerg] 1229#0: bind() to [2a02:c277:2012:6196::1]:443 failed (99: Cannot assign requested address)
journalctl:
10:07:19 vps.klemen.com systemd[1]: Starting LSB: Bring up/down networking...
10:07:20 vps.klemen.com network[638]: Bringing up loopback interface: [ OK ]
10:07:20 vps.klemen.com network[638]: Bringing up interface eth0: [ OK ]
10:07:20 vps.klemen.com systemd[1]: Reached target Network.
10:07:20 vps.klemen.com systemd[1]: Starting Network.
10:07:21 vps.klemen.com systemd[1]: Starting Startup script for nginx service...
10:07:22 vps.klemen.com nginx[1229]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
10:07:22 vps.klemen.com nginx[1229]: nginx: [emerg] bind() to [2a02:c277:2012:6196::1]:443 failed (99: Cannot assign requested address)
10:07:22 vps.klemen.com nginx[1229]: nginx: configuration file /etc/nginx/nginx.conf test failed
10:07:22 vps.klemen.com systemd[1]: nginx.service: control process exited, code=exited status=1
10:07:23 vps.klemen.com systemd[1]: Failed to start Startup script for nginx service.
10:07:23 vps.klemen.com systemd[1]: Unit nginx.service entered failed state.
10:07:23 vps.klemen.com systemd[1]: nginx.service failed.
@Klemen does 2a02:c277:2012:6196::1 exist on the server? is there another service llistening on the port netstat -tulpn | grep 443
Issue persists on the server reboot or nginx could not be started at all?
[root@vps ~]# netstat -tulpn | grep 443
tcp 0 0 5.173.175.128:443 0.0.0.0:* LISTEN 2268/nginx: master
tcp 0 0 0.0.0.0:8443 0.0.0.0:* LISTEN 991/sw-cp-server: m
tcp6 0 0 2a02:c277:2012:6196:443 :::* LISTEN 2268/nginx: master
tcp6 0 0 :::8443 :::* LISTEN 991/sw-cp-server: m
Issue exists only on server reboot, I have to start nginx manually and then it's working
@Klemen, I would recommend you contact our support https://www.plesk.com/contact-support in this case as the issue you have needs deeper investigation.
This solution is not working for Plesk Onyx on Ubuntu 16.04 over AWS EC2.
The only way that I've found to solve it is enabling auto restart on nginx process:
Adding this to `[Service]` section of `/etc/systemd/system/multi-user.target.wants/nginx.service` solves the problem.
# Avoid problem with nginx not starting right after a reboot
Restart=always
RestartSec=5
---- Edit ----
Maybe this problem is related with docker network, since this just happens on my instance that use docker containers, aparently the `network-online.target` is ready after the first interface boots (docker one, probably)
As this answer on Stackoverflow says, this can be fixed by installing the `ifupdown` package. Didn't tested yet, but if this is true, then it should be implemented by default on Plesk!
---- Edit ----
Investigating more, I've found that a service `ifup@` exists, but only watches to eth0 interface, not to docker interfaces. Since I use proxy to docker on some domains, nginx fails to bind to the docker ip since it's not ready yet. So implementing the solution of stackoverflow above should work, making unecessary to add the auto-restart on nginx service.
@Esoares Thank you for sharing your feedback.
Edit ngnix.service is a good idea and works fine, but at next nginx update, this entry are not available!
Is there any other persistent solution?
Hello @Gilberto,
I would like to inform you that directives, added using "systemctl edit nginx.service" command located into /etc/systemd/system/nginx.service.d/override.conf file, that will be available after nginx update.
Also I would like to draw your attention that Plesk uses its own built-in nginx called sw-nginx, designed by Plesk to optimize Plesk services functionality. Hence it is not possible to upgrade/update nginx from OS vendor/third party repositories.
Please sign in to leave a comment.