Restarting Nginx – what does this error message mean?

December 28, 2018 2.3k views
Nginx LEMP Ubuntu 18.04

I followed the official DO tutorial in setting up Nginx server blocks and somehow always end up with an error message that is quite cryptic for me as a beginner. Going back every step I did before I checked for little typing errors, but no semicolons or other things seemed to be missing. Can someone give me a hint what this error message means?

sudo nginx -t
  nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
  nginx: configuration file /etc/nginx/nginx.conf test is successful

sudo systemctl restart nginx
  Job for nginx.service failed because the control process exited with error code.
  See "systemctl status nginx.service" and "journalctl -xe" for details.

systemctl status nginx.service
  nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: en
     Active: failed (Result: exit-code) since Fri 2018-12-28 10:42:09 UTC; 10s ago
       Docs: man:nginx(8)
    Process: 4686 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code
    Process: 4676 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process

Thanks a lot in advance for any help!

1 Answer

@retador

Would you be able to provide the output from the following command?

tail -30 /var/log/nginx/error.log

Tailing the logs may provide a bit more specific detail on what may be causing NGINX to fail to start if you're not seeing anything in the systemctl or journal output.

  • Hi, thanks for responding! Here is the output I got:

    sudo tail -30 /var/log/nginx/error.log
       2019/01/05 15:59:14 [emerg] 30195#30195: bind() to 0.0.0.0:80 failed (98: Address already in use)
       2019/01/05 15:59:14 [emerg] 30195#30195: bind() to [::]:80 failed (98: Address already in use)
       2019/01/05 15:59:14 [emerg] 30195#30195: bind() to 0.0.0.0:80 failed (98: Address already in use)
       2019/01/05 15:59:14 [emerg] 30195#30195: bind() to [::]:80 failed (98: Address already in use)
       2019/01/05 15:59:14 [emerg] 30195#30195: bind() to 0.0.0.0:80 failed (98: Address already in use)
       2019/01/05 15:59:14 [emerg] 30195#30195: bind() to [::]:80 failed (98: Address already in use)
       2019/01/05 15:59:14 [emerg] 30195#30195: bind() to 0.0.0.0:80 failed (98: Address already in use)
       2019/01/05 15:59:14 [emerg] 30195#30195: bind() to [::]:80 failed (98: Address already in use)
       2019/01/05 15:59:14 [emerg] 30195#30195: bind() to 0.0.0.0:80 failed (98: Address already in use)
       2019/01/05 15:59:14 [emerg] 30195#30195: bind() to [::]:80 failed (98: Address already in use)
       2019/01/05 15:59:14 [emerg] 30195#30195: still could not bind()
    

    Still don't really get it tho :-(

    • @retador

      The Address already in use error message indicates there's something else running on the same port that NGINX is attempting to bind to on service start.

      For example, if you're also running Apache on the same server, it'll bind to 80 by default and would prevent NGINX from being able to use the same port. You can check to see if what's running by using either:

      netstat -ltnp | grep -w ':80'
      

      or

      lsof -i :80
      

      If Apache, or another web server is running, you'll want to stop that service and disable it (easiest), or setup a proxy configuration where NGINX proxies requests to Apache (a bit more involved and requires some additional config).

      If Apache happens to be the web server running, you can stop it by using:

      systemctl stop apache2
      

      or

      systemctl stop apache
      

      You can then use disable to prevent the service from starting back up.

      systemctl disable apache2
      

      or

      systemctl disable apache
      

      Important to note that if Apache happens to handling incoming requests currently, you will no longer be able to access any sites until you configure NGINX to handle those requests.

Have another answer? Share your knowledge.