Start nginx on boot - Ubuntu - the solution

4 posts / 0 new
Last post
#1 Tue, 09/18/2018 - 15:42
Luiz Lopes

Start nginx on boot - Ubuntu - the solution


I always wondered why nginx didn't started on boot. Well, it actually did, but too soon. So I needed to change the order. Doing this is not so obvious. That's why I'm posting the solution I found.

The system is Ubuntu 18.04 with Virtualmin and nginx module.

1- First, remove apache to start; Type in the command line: sudo update-rc.d -f apache2 remove

2- Change the order of nginx to start; Access /etc/init.d/nginx; or Webmin > System > Bootup and Shutdown -> Select 'nginx' ; Remove the original 2 lines

# Required-Start:    $local_fs $remote_fs $network $syslog $named
# Required-Stop:     $local_fs $remote_fs $network $syslog $named

And add this 2 lines

# Required-Start:    $remote_fs $network
# Required-Stop:     $remote_fs $network

That´s it. Now nginx will start and work after a system reboot/shudown.

Wed, 11/07/2018 - 18:13

Thank you! I had the issue and your workaround worked.

Also, if nginx is running too soon, it seems a little strange that removing $named would allow the system to boot up properly, since I presume it would start up even earlier?

Just wondering, did you only experience this issue on Ubuntu 18.04? I only had this issue from 18.04 onwards.

Sun, 02/24/2019 - 11:33
Luiz Lopes

Right now the solution pointed up is not working anymore.

Googling... I found a solution (which is more a tweak). You can see link

Which says: 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/' solves the problem.

# Avoid problem with nginx not starting right after a reboot

If you try to edit the file via Virtualmin's Filemanager, you won't be able, because it is a symbolic link. You should do via command line:

sudo nano /etc/systemd/system/
Sun, 08/25/2019 - 04:08

I actually found a simpler solution. The problem was that nginx is slated to run before the IPv6 interface is up, causing it to fail. I made the following changes which seems to work fine:

nano /lib/systemd/system/nginx.service Change to Run systemctl disable nginx.service followed by systemctl enable nginx.service

Topic locked