noyce
By:
noyce

nginx restart failed

September 15, 2017 1.7k views
Ghost Nginx Ubuntu 16.04

I decided to follow the Multiple Blogs Tutorial to set up a second ghost instance on a droplet. Already had a second nginx config file set up to run a second domain and was testing that site. Shut down both ghost and nginx with 'service ghost stop' and 'service nginx stop'. No error messages seen.

Modified the second nginx config file in sites-enabled and attempted to restart nginx with 'service nginx restart'. Saw 'Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.'

The error log shows:

2017/09/15 04:09:48 [emerg] 24518#24518: bind() to 0.0.0.0:80 failed (98: Address already in use)
2017/09/15 04:09:48 [emerg] 24518#24518: bind() to [::]:80 failed (98: Address already in use)
2017/09/15 04:09:48 [emerg] 24518#24518: bind() to 0.0.0.0:443 failed (98: Address already in use)
2017/09/15 04:09:48 [emerg] 24518#24518: bind() to 0.0.0.0:80 failed (98: Address already in use)
2017/09/15 04:09:48 [emerg] 24518#24518: bind() to [::]:80 failed (98: Address already in use)
2017/09/15 04:09:48 [emerg] 24518#24518: bind() to 0.0.0.0:443 failed (98: Address already in use)
2017/09/15 04:09:48 [emerg] 24518#24518: bind() to 0.0.0.0:80 failed (98: Address already in use)
2017/09/15 04:09:48 [emerg] 24518#24518: bind() to [::]:80 failed (98: Address already in use)
2017/09/15 04:09:48 [emerg] 24518#24518: bind() to 0.0.0.0:443 failed (98: Address already in use)
2017/09/15 04:09:48 [emerg] 24518#24518: bind() to 0.0.0.0:80 failed (98: Address already in use)
2017/09/15 04:09:48 [emerg] 24518#24518: bind() to [::]:80 failed (98: Address already in use)
2017/09/15 04:09:48 [emerg] 24518#24518: bind() to 0.0.0.0:443 failed (98: Address already in use)
2017/09/15 04:09:48 [emerg] 24518#24518: bind() to 0.0.0.0:80 failed (98: Address already in use)
2017/09/15 04:09:48 [emerg] 24518#24518: bind() to [::]:80 failed (98: Address already in use)
2017/09/15 04:09:48 [emerg] 24518#24518: bind() to 0.0.0.0:443 failed (98: Address already in use)
2017/09/15 04:09:48 [emerg] 24518#24518: still could not bind()

Attempted to revert back to previous config file. Still fails. Ran 'nginx -t' and saw no syntax errors. Ran 'ps -aux' and see:

root@ghost-1gb-sfo2-01:/etc/nginx/sites-enabled# ps -aux | grep nginx
root     24899  0.0  0.0  12948   940 pts/0    S+   04:34   0:00 grep --color=auto nginx
root     31045  0.0  0.3 126944  3452 ?        Ss   Sep02   0:00 nginx: master process nginx -c /etc/nginx/nginx.conf
www-data 31053  0.0  0.5 127096  6072 ?        S    Sep02   0:11 nginx: worker process

What's going on here? Shouldn't the 'service nginx stop' have killed all the processes? Is that what is causing the restart to fail?

3 Answers

@noyce

You probably have another process listening on ports 80 and 443, paste the output of these two commands to check:

netstat -ltnp | grep 80 and netstat -ltnp | grep 443

# netstat -ltnp | grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      31045/nginx.conf
tcp6       0      0 :::80                   :::*                    LISTEN      31045/nginx.conf
# netstat -ltnp | grep 443
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      31045/nginx.conf

And throwing in the process output for good measure...

# ps -aux | grep nginx
root     25934  0.0  0.0  12948  1016 pts/0    S+   15:21   0:00 grep --color=auto nginx
root     31045  0.0  0.3 126944  3452 ?        Ss   Sep02   0:00 nginx: master process nginx -c /etc/nginx/nginx.conf
www-data 31053  0.0  0.5 127096  6072 ?        S    Sep02   0:12 nginx: worker process
  • The restart fails because 'service nginx stop' failed to stop nginx. I just tried the command line again this morning. nginx is still running, and nothing is written to the error log. Changes to the site are served as expected. Why is this? Does it matter?

    BTW, both /etc/init.d/nginx and /etc/init/nginx exist.

    # ls -l /etc/init/nginx.conf
    -rw-r--r-- 1 root root 401 Apr 26  2016 /etc/init/nginx.conf
    # ls -l /etc/init.d/nginx
    -rwxr-xr-x 1 root root 4579 Apr 26  2016 /etc/init.d/nginx
    

Kill those processes and then try again.
If it makes it any easier then use htop for this.

Have another answer? Share your knowledge.