Question

Nginx not starting: Address already in use (nginx: bind to 0.0.0.0:80 failed)

Posted June 9, 2020 253 views
Linux BasicsNginxUbuntuLinux Commands

Hi all,

I just installed Nginx but when I try to start it it fails with the following error:

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

If I check the status I get the following output:

● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; disabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/nginx.service.d
           └─override.conf
   Active: failed (Result: exit-code) since Mon 2020-06-08 15:59:32 UTC; 5min ago
     Docs: man:nginx(8)
  Process: 3839 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=2)
  Process: 3816 ExecStartPost=/bin/sleep 0.1 (code=exited, status=0/SUCCESS)
  Process: 25445 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
  Process: 25435 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 3813 (code=exited, status=0/SUCCESS)

Jun 08 15:59:30 ubuntu nginx[25445]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jun 08 15:59:30 ubuntu nginx[25445]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Jun 08 15:59:31 ubuntu nginx[25445]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jun 08 15:59:31 ubuntu nginx[25445]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Jun 08 15:59:31 ubuntu nginx[25445]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jun 08 15:59:31 ubuntu nginx[25445]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Jun 08 15:59:32 ubuntu nginx[25445]: nginx: [emerg] still could not bind()
Jun 08 15:59:32 ubuntu systemd[1]: nginx.service: Control process exited, code=exited status=1
Jun 08 15:59:32 ubuntu systemd[1]: nginx.service: Failed with result 'exit-code'.
Jun 08 15:59:32 ubuntu systemd[1]: Failed to start A high performance web server and a reverse proxy server.

Does anyone have any ideas why Nginx would not start?

Thanks!

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.

×
1 answer

Hi there @bitmap,

It would usually mean that you have another service running on the same port. And note that you can not have multiple services listening on the same port.

The service which is already listening on port 80 might be Apache or any other web server listening on port 80.

To check that, you could run the following command:

  • sudo netstat -plant | grep 80

This would show you which service exactly is listening on port 80 and you can then make a decision if you want to have that service as it is or have Nginx instead of it.

If this is indeed Apache, you would need to make a decision whether you want to use Apache or Nginx.

If you want to only have Nginx you have to stop Apache first:

  • sudo systemctl stop apache2

And then start Nginx:

  • sudo systemctl start nginx

If you would like to have Apache and Nginx together, you can follow the steps here on how to setup Nginx as a reverse proxy for Apache:

https://digitalocean.com/community/tutorials/how-to-configure-nginx-as-a-web-server-and-reverse-proxy-for-apache-on-one-ubuntu-18-04-server

Another thing that I could recommend is checking the answer here on how to troubleshoot common Nginx problems:

https://www.digitalocean.com/community/questions/how-to-troubleshoot-common-nginx-issues-on-linux-server

I hope that this helps and let me know if you have any other questions!

Regards,
Bobby

by Jesin A
In this tutorial you'll configure Nginx as both a web server and as a reverse proxy for Apache to host four domains on a single server.
Submit an Answer