104

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!

Eliah Kagan
  • 119,640
Huw
  • 1,603
  • 3
  • 17
  • 23

8 Answers8

164

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.

Eliah Kagan
  • 119,640
Dlloyd
  • 1,756
49

Run this command you can find problem.

sudo nginx -t
Nanhe Kumar
  • 1,409
8

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;
Eliah Kagan
  • 119,640
Arvind07
  • 180
  • 1
  • 3
6

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

4

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.

Ravexina
  • 57,256
Anto
  • 191
  • 1
  • 3
3

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.

user.dz
  • 49,176
kenisfis
  • 31
  • 1
2

Need to purge nginx then type at command line:

ln -s /etc/nginx/sites-availbale/default .etc/nginx/sites-enabled/default
RolandiXor
  • 51,797
1

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.