Question

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

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!


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Accepted 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:

  1. 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:

  1. sudo systemctl stop apache2

And then start Nginx:

  1. 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

And here is also a quick video demo on how to troubleshoot such issues as well:

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

Regards, Bobby

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

This comment has been deleted