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

Hi,

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
trenzterra

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 https://support.plesk.com/hc/en-us/articles/213908925-Nginx-does-not-sta...

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/multi-user.target.wants/nginx.service' solves the problem.

# Avoid problem with nginx not starting right after a reboot
Restart=always
RestartSec=5

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/multi-user.target.wants/nginx.service
Sun, 08/25/2019 - 04:08
trenzterra

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 After=network.target to After=network-online.target Run systemctl disable nginx.service followed by systemctl enable nginx.service

Topic locked