Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

nginx will not start because port 80 is already taken

Errorbind() failed (98: Address already in use)

Short answer

Error 98 means another process already listens on the address and port that nginx wants. Find the owner with ss. It is either a leftover nginx that was never shut down, or a different server such as Apache. Stop it, or change the listen port in your nginx config.

  • Applies to nginx 1.26, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    List the listening TCP sockets on port 80 together with the process that owns each one.

    sudo ss -ltnp 'sport = :80'
  2. 2Match what you see, then jump to its fix

    1. 1ss shows users:(("nginx",pid=...)) on the port you are trying to bindAn older nginx is still runningFix
    2. 2ss shows another program name, such as apache2 or httpd, on port 80A different server owns the portFix

What does the error look like?

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

Cause 1 of 2

An older nginx is still running

1Check

A previous master process that was started by hand, or never stopped, keeps the socket. Look for nginx master processes.

sudo ss -ltnp 'sport = :80'
ps aux | grep "[n]ginx: master"

2Fix

Shut the old instance down gracefully with the quit signal, then start nginx once.

sudo nginx -s quit
sudo nginx

3Verify

nginx should be the only listener, and the configuration should test clean.

sudo nginx -t
sudo ss -ltnp 'sport = :80'

Confirmed by nginx.org

Did this fix it?

Cause 2 of 2

A different server owns the port

1Check

The -p column of ss names the owner. Only one process can listen on one address and port unless a socket option such as reuseport is set.

sudo ss -ltnp 'sport = :80'

2Fix

Stop or reconfigure the other server, or give nginx a different port. A listen directive without a port means 80 as root.

server {
    listen 8080;
    server_name example.com;
}

3Verify

Test the config, start nginx, and confirm it appears in the listener list.

sudo nginx -t && sudo nginx -s reload
sudo ss -ltnp 'sport = :8080'

Confirmed by nginx.org

Did this fix it?

How do I stop it coming back?

  • Stop nginx with nginx -s quit or the service manager, not by killing a worker process.
  • Decide which server owns ports 80 and 443 on the host, and keep every other web server off them.
  • Run ss -ltnp before installing a second web server.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.