Nginx failing to reload - how to track down why?

214,757

Solution 1

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.

Solution 2

Run this command you can find problem.

sudo nginx -t

Solution 3

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;

Solution 4

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!!

Solution 5

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.

Share:
214,757

Related videos on Youtube

Huw
Author by

Huw

Updated on September 18, 2022

Comments

  • Huw
    Huw almost 2 years

    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!

    • Lekensteyn
      Lekensteyn about 10 years
      Check your syntax with sudo nginx -t (or sudo nginx -p /etc/nginx -c nginx.conf where /etc/nginx is your configuration prefix and nginx.conf the main config file).
    • Huw
      Huw about 10 years
      sudo nginx -s reload also seemed to give me a readout!
  • Huw
    Huw about 10 years
    ah ha! very useful I seem to be getting:location "/blog/wp-admin" is outside location "/blog/.*\.php$" in /etc/nginx/site-configs/wordpress.conf:1 ... interesting, gives me something to go on!
  • Huw
    Huw about 10 years
    ARGH! Three hours of searching and it turns out I'd missed a ; Thanks for all the help, proved essential in tracking it down. Incidentally if anyone ever ends up at this question after following the Ars Technica Web-served posts. I think I've been through them with a fine tooth comb now!
  • Panther
    Panther about 9 years
    You do not have to remove and purge, just purge. And hard to know if this is goin gto answer the question as purge will remove all config files.
  • Huw
    Huw about 9 years
    Ideally - and for other users I would have preferred to get the maximum amount of readout as to where the failure was occurring and repair my current install instead of purging and starting from scratch
  • Aaron Lelevier
    Aaron Lelevier about 9 years
    @bodhi.zazen I corrected my answer. And as for what "Huw" said, I agree. It's just that I was at the beginning of installing and setting up nginx so it wasn't a big deal to just remove it and start over instead of tracing down the error. Thank you both for your insite.
  • Jason Southwell
    Jason Southwell almost 9 years
    Do you mean apt-get purge?
  • Zack
    Zack over 8 years
    Note: if your permissions are wrong on /var/log/nginx/error.log, nginx will not be able to write the error to it and will fail silently. Checking your config as in the accepted answer (nginx -c /etc/nginx/nginx.conf -t) will help.
  • Bill Garrison
    Bill Garrison over 8 years
    running this command gives me nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful and yet i still can't get nginx to start
  • Dlloyd
    Dlloyd over 8 years
    @BillGarrison check syslog and the nginx error log for more info
  • Sizzling Code
    Sizzling Code over 5 years
    in my case i only i had to start using this command sudo /etc/init.d/nginx start