Nginx does not start after server reboot

I switched from the built-in version of src nginx 1.2.6 to 1.4.1 on Ubuntu 13.04.

Installed via Ubuntu PPA, http://wiki.nginx.org/Install#Ubuntu_PPA . It all worked great.

Manually, I can restart / start / stop the service using

sudo service nginx <command> 

After rebooting the server, nginx does not fit on its own.

In my previous manual installation, I had a manually written Upstart script in / etc / init, which worked fine. The PPA installation installed /etc/init.d/script, so I would like to stick with the PPA methods and not hack something.

Perhaps because I am not very familiar with the service interface, there is something missing for me.

I also checked /var/log/nginx/access.log and error.log and did not see anything recorded during the startup process.

What should I do to fix this?

+15
ubuntu nginx
source share
5 answers

sudo update-rc.d nginx enable worked for me.

+28
source share

I don't have much experience with Ubuntu, but have you tried running chkconfig?

You can try:

 # sudo update-rc.d nginx defaults 

Or:

 # sudo apt-get install chkconfig # sudo chkconfig nginx on 
+16
source share

UPDATE March 28, 2016

I presented a small improvement to the Ubuntu Upstart script, which I proposed below, as a request for craving for the NGinX wiki. My transfer request was accepted and the patch was merged .


I am on Ubuntu 14.04 LTS and had the same problem; NginX can start normally with sudo service nginx restart , but it did not start automatically when the server started.

I followed the instructions on the NGinX Ubuntu Upstart Wiki page, but it did not work ( initially ). So I rummaged a bit. At first, I discovered that Ubuntu tried to start NGinX at startup, but failed:

 $ sudo cat /var/log/boot.log ... * Starting nginx http daemon [fail] ... 

Then I found the upstart initialization log file:

 $ cat /var/log/upstart/nginx.log ... nginx: [emerg] host not found in upstream "<mydomain>:443" in /etc/nginx/sites-enabled/mydomain:2 ... 

So, I realized that the launch of the NGINX script was started before the network interface was started. This server error response gave me the hints needed to fix the NginX Ubuntu Upstart script. Thus, '!', IFACE=lo must be changed to IFACE!=lo . For convenience, I inserted the full script below:

 # nginx description "nginx http daemon" author "George Shammas <georgyo@gmail.com>" start on (filesystem and net-device-up IFACE!=lo) stop on runlevel [!2345] env DAEMON=/usr/sbin/nginx env PID=/var/run/nginx.pid expect fork respawn respawn limit 10 5 #oom never pre-start script $DAEMON -t if [ $? -ne 0 ] then exit $? fi end script exec $DAEMON 

After rebooting, I checked if NGinX is running now:

 $ sudo initctl list | grep nginx nginx start/running, process 1551 

I will inform the author of this script about my findings.

+1
source share

In addition to the Visionscaper nginx request, installed from standard trusted repositories, it uses the sysvinit service file, not upstart. Thus, instead of the nginx service for upstart, edit rc-sysinit upstart service. For this, it is recommended to use upstart overrides:

 # echo "start on (filesystem and net-device-up IFACE!=lo) or failsafe-boot" > /etc/init/rc-sysinit.override 
0
source share

For Ubuntu:

First check its status to make sure it does not throw an error

 systemctl status nginx.service 

It will either show an error or show that it is not running

If it did not start then it should be included

 sudo /etc/init.d/systemctl enable nginx sudo reboot 
0
source share

All Articles