Nginx config for enabled sites does not appear to be taking effect any more

Posted November 28, 2013 56.7k views
I'm trying to get my server setup to handle multiple wordpress sites on nginx. I followed the different tutorials in the initial server setup, lemp installation etc. Everything was working ok with the exception of permalinks not working at all. I couldn't navigate to any page on the front end (away from the domain root). So since then I have tried a lot of different things messing with nginx.conf and other files (from instructions in the wp codex), but none of that helped, so since then I've tried to go back to a clean slate with nginx and php-fpm. I uninstalled them both, purged, autocleaned, and reinstalled them. After this, I've gone through the basics again and nginx is running, but something is still very wrong. When I go to my server IP, I get the "It works!" index.html from /var/www/ but my configuration should be pointing it to a different document root. my nginx.conf looks like this: my only file in sites-enabled looks like this: From what I understand, it should be picking up my site's configuration in sites-enabled rather than loading this file. I'm stumped, please help.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

20 answers
Is nginx running? What's the output of
sudo netstat -plutn | grep 80
I forgot to check if it was already running before starting, but started it with no errors - although I think it was already running. The tail command produces no output.

I'm ready to give up and start over at this point. I appreciate your help.
Are there any files in /etc/nginx/conf.d/?
whoa, apache2?

`tcp 0 0* LISTEN 14646/apache2`

Well there we go..
I don't remember ever installing it. I started with a clean Ubuntu 12.04 digital ocean image (not a LAMP one) and only followed the nginx tutorials.

Now when I stop apache and restart nginx & fpm, nothing is coming up any more in the browser and when I run that same netstat grep, nothing comes up.

Where to go from this point?
Uninstall apache and reboot your droplet:
sudo apt-get remove apache2

sudo reboot

If nginx doesn't work, check its error logs and see what it's not starting.
When I issue that command I get:

Package apache2 is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 136 not upgraded.

but if I type
which apache2
I get

After reboot Apache2 and nginx are both running
Hmm. What's the output of
sudo dpkg --get-selections | grep apache
apache2-mpm-prefork install
apache2-utils install
apache2.2-bin install
apache2.2-common install
libapache2-mod-php5 install
Okay, so the apache binaries are installed. You don't need any of these packages, so uninstall them and reboot your droplet:
sudo apt-get remove apache2* libapache2*

sudo reboot
The following packages will be REMOVED:
apache2-mpm-prefork apache2-utils apache2.2-bin apache2.2-common libapache2-mod-php5

Apache is gone now, nginx is running but does not seem to be listening for traffic on port 80 as it is setup in my config.

If I run 'sudo netstat -plutn | grep 80', nothing comes up.

Thanks for all your help!
Are you sure tha tnginx is running? What's the output of
sudo ps -wwaux | grep nginx
Warning: bad ps syntax, perhaps a bogus '-'? See
root 1541 0.0 0.1 10252 884 ? Ss 02:40 0:00 nginx: master process /usr/sbin/nginx
www-data 1542 0.0 0.2 10392 1288 ? S 02:40 0:04 nginx: worker process
www-data 1543 0.0 0.2 10392 1288 ? S 02:40 0:04 nginx: worker process
www-data 1544 0.0 0.2 10392 1288 ? S 02:40 0:04 nginx: worker process
www-data 1545 0.0 0.2 10392 1288 ? S 02:40 0:00 nginx: worker process
1000 2122 0.0 0.1 4368 812 pts/0 S+ 15:48 0:00 grep --color=auto nginx
Hmm. What's your droplet's IP address? Also, which port is nginx listening on?
sudo netstat -plutn | grep nginx
My droplet's ip is

That command gives no output.

According to what I can see in the nginx conf files it should be listening on 80.

What else to check?
That means nginx is not running. Try starting it:
sudo service nginx start

If that does not work, try seeing what the error is:
sudo tail /var/log/nginx/error.log
Well.. I've already made some good progress with a clean re-image.

I think my problem came down to the symlink I was making between the sites-available config file to the sites-enabled folder.

On the old install, my site's config file in the sites-enabled folder was glowing in the terminal. I thought it was because it was a symlink, but now I think it was indicative of pointing to a location that didn't exist.
I didn't really notice anything was different because I had followed one of the tutorials which had instructed me to remove the default config file from the sites-enabled directory.

This is how I was creating the link:
/etc/nginx$ sudo cp sites-available/default sites-available/one
/etc/nginx$ sudo ln -s sites-available/one sites-enabled/one

to which I investigated to find:

/etc/nginx$ ls -l sites-enabled/
total 0
lrwxrwxrwx 1 root root 34 Dec 8 05:10 default -> /etc/nginx/sites-available/default
lrwxrwxrwx 1 root root 19 Dec 8 05:20 one -> sites-available/one

Oops! So that explains why my config files were not being loaded.

After creating that link properly, it seems to be working now!

What can I say other than I guess that was a hard lesson learned, but at least I figured it out!

Thanks for your help again!
Sweet! Glad to hear it's working now :]

I hope this doesn’t bump this old thread but THANK YOU. I’ve done this quite a few times and could not figure out why it wasn’t working. I thought my version of Nginx had gone mad. Nope, I just forgot how to symlink…

I know I am late to the party, but for those who find this through google:
Try launching the url from a different browser before making those changes listed above ;)

Explanation: If you set a bogus redirect rule in a file with a permanent switch, most browsers will remember this rule and cache it. For example chrome caches it in some internal file that can not be cleared by removing cookies and site data - you have to actually clear full browser history and all browsing data for the last x hours.

Submit an Answer