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.

Solutions

There are several workarounds:

  1. Modify /usr/lib/systemd/system/nginx.service and add network-online.target to the “After=” in the unit section:
    # vi /usr/lib/systemd/system/nginx.service
    [Unit]
    Description=Startup script for nginx service
    After=network-online.target network.target remote-fs.target nss-lookup.target
    This workarounds is only temporary until the next yum update, where nginx.service might be overwritten with a newer systemd script version.
  2. 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.
  3. 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:
    # vi /etc/sysctl.d/daemon-offbind.conf
    net.ipv4.ip_nonlocal_bind = 1
    net.ipv6.ip_nonlocal_bind = 1
    On next reboot nginx and all other services dependent on an online network interface will bind nontheless.

Conclusion

Solution 3 is imho the preferred solution as of now. It works always and is still active, even after an update.