Ubuntu: Nginx failing to reload - how to track down why?


Hi I've had my Nginx server running great on Ubuntu server 12.04 for a while.

I've been gradually bolting on various bits, and got as far as optimising load times on my wordpress page.

After making a few changes to my hosts file I decided to:

sudo /etc/init.d/nginx reload  

To which I get:

  • Reloading nginx configuration nginx [fail]

No additional info or reasoning is given. How can I restart my server so that it prints any error statements whilst reloading so I can begin to track down the error.

For a bonus question:

For those Nginx sysadmins, when you've made a bunch of changes to hosts and bolted on a few other bits and suddenly your nginx server won't reload (incidentally everything still appears to be running!) how do you begin your approach to isolating why or begin breaking things down to debug!


Check syslog (/var/log/syslog) for messages about config file issues.

From the commandline you can run nginx -c /etc/nginx/nginx.conf -t to have nginx check your configuration for errors.


Run this command you can find problem.

sudo nginx -t  


You should probably check for errors in /var/log/nginx/error.log.

In my case I did no add the port for ipv6. You should also do this (in case you are running nginx on a port other than 80): listen [::]:8000 default_server ipv6only=on;


Check your /etc/nginx/sites-available/default or whatever copy of it you're using, and make sure you uncomment (remove #) any } you may need in relation to the { that likely was uncommented. That was my issue.


I ran these commands to get nginx back up and working:

# remove nginx conf files  apt-get purge nginx    # reinstall  apt-get install nginx    # make sure the default site is enabled  ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default    # start nginx  sudo /etc/init.d/nginx start   

nginx is now working!!


Need to purge nginx then type at command line:

ln -s /etc/nginx/sites-availbale/default .etc/nginx/sites-enabled/default  


do a reopen all files, using

nginx -s reopen  

then use

nginx -s reload  

As nginx help shows that it will, reload the nginx by sending the signal to master process.it should work.

Request: please donot provide purge commands without caution, since it may cause issue for beginners (all configurations will be lost).... A BIG trouble.


If it is giving you such errors you can check journalctl -xe out.
It has bunch of information about what happened in an operation system matter.
you can find the line or simply journalctl -xe | grep nginx to find what has happened to nginx when it tried to run itself.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »