99

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!

| improve this question | | | | |
  • 4
    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). – Lekensteyn Apr 5 '14 at 21:13
  • sudo nginx -s reload also seemed to give me a readout! – Huw Apr 5 '14 at 23:23
154

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.

| improve this answer | | | | |
  • 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 Apr 5 '14 at 23:24
  • 2
    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! – Huw Apr 5 '14 at 23:51
  • 4
    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 – Bill Garrison Nov 19 '15 at 18:44
  • 1
    @BillGarrison check syslog and the nginx error log for more info – Dlloyd Dec 3 '15 at 23:19
46

Run this command you can find problem.

sudo nginx -t
| improve this answer | | | | |
7

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;

| improve this answer | | | | |
  • 1
    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. – user898763452 Oct 26 '15 at 16:44
5

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

| improve this answer | | | | |
  • 2
    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. – Panther Apr 20 '15 at 2:37
  • 1
    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 – Huw Apr 20 '15 at 17:07
  • 1
    @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. – Aaron Lelevier Apr 21 '15 at 22:47
  • in my case i only i had to start using this command sudo /etc/init.d/nginx start – Sizzling Code Oct 2 '18 at 23:05
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.

| improve this answer | | | | |
2

Need to purge nginx then type at command line:

ln -s /etc/nginx/sites-availbale/default .etc/nginx/sites-enabled/default
| improve this answer | | | | |
  • Do you mean apt-get purge? – RolandiXor Sep 1 '15 at 16:31
2

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.

| improve this answer | | | | |
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.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.