nginx: bind() to 0.0.0.0:80 failed (98: Address already in use)
Port 80 belongs to something else: an old nginx master, Apache, or a published container. Locate the listener, then fix the duplicate listen lines.

Introduction & Quick Summary
nginx will not start, or will not reload:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()98 is the Linux errno EADDRINUSE: the socket the configuration asks for is already owned by another process, or by another socket in the same process. The message repeats per listen line, so a config with both IPv4 and IPv6 addresses prints two lines and then summarises.
Quick answer:
sudo ss -ltnp 'sport = :80' # who owns the port, protocol, address
sudo lsof -iTCP:80 -sTCP:LISTEN
sudo ss -ltnp 'sport = :443'Kill or stop that owner, or move nginx to another port — but decide which one you actually want, because the owner is often a second copy of nginx that survived a failed restart.
The four processes that most often hold port 80 on a Linux host: an nginx master left over from a manual nginx -s stop that did not finish, Apache or httpd, docker-proxy because a container published -p 80:80, and a Caddy or Node process started by a developer. On a fresh cloud image it is usually Apache, which the distribution enabled by default while nginx was installed alongside it.
Core Mechanics, Signatures & Reproducible Setup
nginx binds one listening socket per listen directive after dropping privileges, but before writing its PID file. A bind failure aborts the whole startup, so a single conflicting line prevents every other port from being served.
Address semantics matter more than they look:
server {
listen 80; # 0.0.0.0:80 (IPv4 wildcard)
listen [::]:80; # [::]:80 with ipv6only=on by default
listen 127.0.0.1:8080; # loopback only
listen 80 default_server; # catch-all for unmatched Host
}listen 80 and listen [::]:80 are different sockets on Linux, even though a client can reach both. ipv6only=off on the IPv6 socket makes it accept IPv4-mapped connections too, which then conflicts with the explicit IPv4 listen and produces the second line of the error above.
Reproduce both cases on a spare port without touching production:
sudo nginx -c /dev/null # control: starts with no config
python3 -m http.server 8080 & # occupies 8080
echo 'server { listen 8080; }' | sudo tee /etc/nginx/conf.d/repro.conf
sudo nginx -t && sudo nginx # bind() to 0.0.0.0:8080 failed (98)
kill %1 && sudo nginx # succeeds once the port is freenginx -t validates syntax and does not bind, which is why a configuration can pass -t and still fail at startup.
Key Comparison Table
The errno in the message is the fastest classifier:
| Message | errno | Cause | Fix |
|---|---|---|---|
98: Address already in use | EADDRINUSE | another listener owns the address | stop the owner or change the port |
13: Permission denied | EACCES | binding a port below 1024 as non-root | grant CAP_NET_BIND_SERVICE or use a high port |
99: Cannot assign requested address | EADDRNOTAVAIL | the address does not exist on this host | fix the listen address |
97: Address family not supported | EAFNOSUPPORT | IPv6 listen on an IPv4-only host | remove [::] lines |
still could not bind() | summary | several listen lines failed | fix them all before restarting |
Finding the owner:
| Tool | Command | Notes |
|---|---|---|
ss | ss -ltnp 'sport = :80' | shows process name and PID, needs root |
lsof | lsof -iTCP:80 -sTCP:LISTEN | works on macOS too |
fuser | fuser -n tcp 80 | prints PIDs only, useful in scripts |
systemctl | systemctl status nginx apache2 httpd | shows which unit owns a master |
docker | docker ps --format '{{.Names}} {{.Ports}}' | rows with 0.0.0.0:80-> are the cause |
Where the conflict is configured, by deployment shape:
| Shape | Usual occupant | Where to look |
|---|---|---|
| host with nginx + Apache | Apache on 80, nginx on 8080 | /etc/apache2/ports.conf |
| nginx in Docker | host nginx, or docker-proxy | docker ps, compose ports: |
| Kubernetes ingress | host nginx from the host OS | hostPort in the DaemonSet |
| laptop, dev server | a previous npm run dev | ss, or lsof |
Practical Edge Cases, Error Fixes & Deep Dive Code Examples
1. A failed restart leaves two masters
systemctl restart nginx stops the old master and starts a new one. When the stop times out, the unit is marked failed but the old master keeps the sockets, and the start fails with EADDRINUSE:
sudo systemctl status nginx --no-pager
ps -eo pid,ppid,cmd | grep '[n]ginx'
sudo systemctl stop nginx
sudo pkill -TERM -f 'nginx: master' # only if the unit is genuinely stuck
sleep 2 && sudo systemctl start nginxPrefer sudo nginx -s reload for configuration changes: reload passes the existing sockets to new workers and never rebinds, so a live master cannot conflict with itself.
2. Docker published port
docker ps --format 'table {{.Names}}\t{{.Ports}}' | grep ':80->'
# web 0.0.0.0:80->80/tcp
docker compose down # or change the host side: "127.0.0.1:8080:80"The listener is docker-proxy, not the container process, so ss attributed the port to a name you do not recognise. Binding the published port to 127.0.0.1 keeps it reachable only through nginx, which is usually the intent.
3. The IPv6 listener that blocks IPv4
# both sockets, the recommended form
listen 80;
listen [::]:80;
# one dual-stack socket; the IPv4 line must then be removed
listen [::]:80 ipv6only=off;Keeping ipv6only=off and listen 80 together produces exactly the pair of messages in the introduction: the IPv6 socket already covers IPv4 and the second bind fails.
4. Ports below 1024 without root
sudo setcap 'cap_net_bind_service=+ep' /usr/sbin/nginx
# or, for containers, keep the default user and raise the floor
sudo sysctl -w net.ipv4.ip_unprivileged_port_start=80The setcap route is lost on every nginx upgrade, since the package replaces the binary. In a container, ip_unprivileged_port_start inside the net namespace is the portable option, and it is what Kubernetes does for you when a pod requests a low port.
5. default_server duplicates
Two server blocks with default_server on the same listen address fail with a different message:
nginx: [emerg] a duplicate default server for 0.0.0.0:80 in /etc/nginx/sites-enabled/a.conf:3
That one names the file, so it is easier. It appears after copying a vhost file and forgetting to change the flag, and grep -rn default_server /etc/nginx finds both.
6. Reload versus restart semantics
A restart closes and reopens sockets; a reload keeps them. On a busy host, a reload during a deploy is safer even for a port change — but a port change is one of the few things a reload cannot apply, because the listening set changes. Confirm the live listening set after any change:
sudo ss -ltnp | grep nginx
sudo nginx -T | grep -n 'listen'nginx -T prints the merged configuration including includes, which is the only way to see which file actually contributed a listen line.
Common Compilation/Runtime Mistakes & Version Gotchas
Killing by PID file. cat /var/run/nginx.pid | xargs kill fails silently when the PID file is stale and the number belongs to another process. Match on the command line (pgrep -a nginx) instead.
Assuming TIME_WAIT blocks the bind. Closed connections sit in TIME_WAIT for a minute, but nginx sets SO_REUSEADDR on listening sockets, so those sockets do not conflict. ss -tan state time-wait showing thousands of entries is normal and not the cause.
Editing a vhost and reloading when the failure is in another file. sites-enabled is usually a symlink farm; a stale link to a deleted file still loads. nginx -T plus the line number in the [emerg] message identifies the contributing file.
Version differences. nginx 1.25.1 moved the http2 parameter off listen into a standalone http2 on; directive, and configurations using listen 443 ssl http2; now emit a deprecation warning that fails -t under error_log ... warn. reuseport requires kernel 3.9 or later and is not enabled by default; adding it to every listen line lets several nginx instances bind the same port, which surprises anyone who expects the second one to fail. The [::] default changed from ipv6only=off to on in nginx 1.3.4, so advice written for older releases reverses the fix.
Verifying from the outside. Once nginx starts, the port is not proof the site is reachable: a firewall rule or a security group can still drop traffic. The CIDR calculator confirms whether a client address falls inside the allowed range, and the HTTP status code reference distinguishes a connection refusal from a 502 returned by a reverse proxy that is up but cannot reach its upstream.
Reference material: ngx_http_core_module listen directive and the nginx beginner's guide.
Official references
primary documentationThe Linux documentation that defines the behaviour this guide explains.
Try matching browser tools
All toolsSmall utilities that fit Linux work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Linux guides
All Linux guidesnginx 502 Bad Gateway: upstream connection refused
The log line names the address and errno, which is the diagnosis. Fix the host, the start-up order, the buffers, or the timeout that actually fired.
Linux: Read-only file system (EROFS) on a mounted volume
EROFS is a mount condition, not a permission error. Read the kernel log first: I/O errors, a full thin pool, an ro fstab entry or a read-only root.
apt: The repository does not have a Release file
apt disables any repository whose Release file returns 404. Correct the suite name, move an end-of-life release to the archive host, or remove a dead repo.
Linux: bind: Cannot assign requested address
EADDRNOTAVAIL means the kernel had no address to bind: too many TIME_WAIT sockets, an IP missing from the interface, or a wrong listen address.
More in Linux
All Linux guidesThe guides filed next to this one in Linux, in library order.