Probable reasons why Nginx does not start after reboot:

  • Nginx is not added to autostart;
  • Nginx starts before network services are loaded. In this case, it is necessary to delay the launch of Nginx.

How to add Nginx to autostart


  1. Execute the command:

    systemctl enable nginx
    CODE
  2. Reboot the server and check if Nginx is running:

    service nginx status
    CODE

How to delay the launch of Nginx


Method 1

  1. Replace the line /etc/systemd/system/multi-user.target.wants/nginx.service in the configuration file Nginx:

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

    with:

    After=network-online.target remote-fs.target nss-lookup.target
    CODE
  2. Reboot the server and check if Nginx is running:

    service nginx status
    CODE

Method 2

  1. Add the string to the Nginx Service section configuration file /etc/systemd/system/multi-user.target.wants/nginx.service:

    ExecStartPre=/bin/sleep <time>
    CODE
    Comments

    <time> — start delay in seconds. It is recommended to set the start delay of 10 seconds.

  2. Reboot the server and check if Nginx is running:

    service nginx status
    CODE