There are a lot of possible issues on why nginx does not start upon reboot. Yet a more common reason is tied to systemd and NetworkManager, which is the default service to manage network connections in RHEL 7+, CentOS 7+,… With network.service the dependency “After=network.target …” is sufficient, but with NetworkManager.service it is not. As a result, the network interface is not online upon nginx startup. In return, nginx does not bind to an offline network device by default. So nginx does not start on reboot.
There are several workarounds:
- Modify /usr/lib/systemd/system/nginx.service and add network-online.target to the “After=” in the unit section:This workarounds is only temporary until the next yum update, where nginx.service might be overwritten with a newer systemd script version.
- A solution would be to just enable NetworkManager-wait-online.service for the network devices going online. For that simply activate the NetworkManager-wait-online.service:
systemctl enable NetworkManager-wait-online.service
Depending on your system (e.g. mixed IPv4 and IPv6), this solution might not work, when the IPv4 part is online, but the IPv6 part is not yet. Again nginx can not bind (only IPv6 in this case) and fails.
- Another option is to allow nginx to bind to network devices, which are not already online. Create the file daemon-offbind.conf and add the shown configuration:On next reboot nginx and all other services dependent on an online network interface will bind nontheless.
Solution 3 is imho the preferred solution as of now. It works always and is still active, even after an update.