nginx will not start because port 80 is already taken
bind() 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.
Fix it fast
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'2Match what you see, then jump to its fix
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 nginx3Verify
nginx should be the only listener, and the configuration should test clean.
sudo nginx -t
sudo ss -ltnp 'sport = :80'Confirmed by nginx.org
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
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
Servers
A Let's Encrypt certificate did not renew with Certbot
Type: connection ... Timeout during connect (likely firewall problem)
Run sudo certbot renew --dry-run and read the Type and Detail lines.
6 causes, each with a fixServers
curl cannot connect to port 80 or 443 on a server running nginx
CURLE_COULDNT_CONNECT (7): Failed to connect() to host or proxy
Exit code 7 means the TCP connection itself failed, before any HTTP happened.
3 causes, each with a fixServers
Django returns a 500 behind Gunicorn and the traceback is nowhere
The traceback shows locally with runserver but not under Gunicorn
With DEBUG set to False, Django's default logging does not print errors to the console.
2 causes, each with a fixServers
Your website on a Google Compute Engine VM times out on port 80
The site works with curl on the VM but not from outside
A timeout, as opposed to a refusal, usually means a firewall dropped the packets.
3 causes, each with a fixServers
Gunicorn rejects a request with "Error parsing headers: limit request headers fields size"
Error parsing headers: 'limit request headers fields'
Gunicorn caps the size of one header field at 8190 bytes and the number of headers at 100 by default.
2 causes, each with a fixServers
HAProxy answers 503 "No server is available to handle this request"
No server is available to handle this request.
HAProxy sends 503 when it has no server to give a request to.
4 causes, each with a fix