2

I tried installing an HTTPS certificate, and after banging my head against the wall for a few hours, I realized that Nginx is NOT picking up the changes I made in my site configuration files contained within /etc/nginx/sites-available/

When I run service nginx restart it restarts fine. When I run nginx -t it says my syntax is OK and my config test is successful. However, when I run service nginx reload I get an error that says reload: Not running

When I look in /var/log/nginx/error.log I have these errors.

2016/08/29 16:04:40 [emerg] 14744#14744: bind() to 0.0.0.0:80 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: bind() to 0.0.0.0:443 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: bind() to [::]:80 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: bind() to 0.0.0.0:80 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: bind() to 0.0.0.0:443 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: bind() to [::]:80 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: bind() to 0.0.0.0:80 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: bind() to 0.0.0.0:443 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: bind() to [::]:80 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: bind() to 0.0.0.0:80 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: bind() to 0.0.0.0:443 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: bind() to [::]:80 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: bind() to 0.0.0.0:80 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: bind() to 0.0.0.0:443 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: bind() to [::]:80 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: still could not bind()

After Googling around, I ran across this command netstat -plutn | grep 80 which gives me...

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      14642/nginx: worker
tcp6       0      0 :::80                   :::*                    LISTEN      14642/nginx: worker

I have no idea what this really means, but reading around, it seems Nginx should NOT be running on port 80? Nginx is my webserver, don't I want it running on port 80?

Not sure how to proceed. I want Nginx to pick up the changes I made in my site config files with the service nginx reload command, and at the same time I'm hesitant to just copy/paste commands I find around the net since I have 10 websites hosted on this server.

Where am I going wrong? I have tried deleting the default file in my sites-available folder as some have suggested, but I just don't really understand what the problem is, and how to fix it.

4
  • 2
    Could be that it's already running and you're trying to run it again. Something like "ps -ef | grep nginx" will tell you if it's running already, but your netstat suggests it is. Try stopping and starting nginx, which I do with "service nginx restart". You can also use "nginx -s reload", as described here. nginx.org/en/docs/beginners_guide.html . For further help post your nginx and site configurations.
    – Tim
    Aug 29, 2016 at 23:24
  • I have run "service nginx restart" about 100 times now, my updated config is still not taking effect. Something is blocking my updated configs to be reloaded Aug 29, 2016 at 23:26
  • This is why I asked for the ps. Instead of restart you need to stop it, ensure it's stilled with a kill command, then start it again, like the answer below says.
    – Tim
    Aug 29, 2016 at 23:39
  • When I run the ps command right now I get this Aug 29, 2016 at 23:41

2 Answers 2

2

Problem is fixed. As Tim said, I ran the ps -ef | grep nginx command and manually ran kill PID for all the processes. Then I ran service nginx restart and all worked well. When I then ran service nginx reload I did NOT get an error, and my HTTPS cert now works. Thanks Tim and dmourati for your assistance

0

Sounds like a problem with your init script and the pid file location for nginx. You can manually kill nginx like so:

sudo kill 14642

Then start nginx via the init script as follows:

sudo service nginx start

From there, if you copy/paste your init script and nginx.conf file, I'm sure we can find the problem with the pid.

1
  • I see my PID value changing each time I kill it. When I run netstat -plutn | grep 80 I can see the updated PID is 14839. When I then kill it with kill 14839 and immediately re-run netstat -plutn | grep 80 I can see I have a new PID, 14859. My nginx.conf is here and my /etc/init.d/nginx script is here Aug 29, 2016 at 23:39

Not the answer you're looking for? Browse other questions tagged .