nginx: [emerg] bind() to the all-interfaces address:80 failed (98: Address already in use)
Fixes nginx failing to start because port 80 is already bound, by finding the occupying process and either stopping it or moving nginx to another port. Not for permission or config-syntax errors.
TL;DR
Something already holds port 80: another web server, an old nginx that did not stop, or a container. Find it with ss, stop it or move it, then start nginx. nginx binds cleanly once the port is free.
Error
nginx: [emerg] bind() to the all-interfaces address:80 failed (98: Address already in use)Steps
- Find the occupant: run
ss -tlnpand look at the process attached to port 80. Expected: a concrete process name and PID, often another nginx or apache. - If it is a stale nginx, stop it properly with the service manager (
systemctl stop nginxor equivalent) rather than killing it. Expected: the port frees up. - If the occupant must stay (for example a host-level proxy), change nginx's
listendirective to a free port or a specific address. Expected: no more bind conflict. - Validate the config: run
nginx -t. Expected: syntax ok and test successful. - Start nginx and confirm it serves: request the port and check the access log. Expected: HTTP 200s instead of emerg errors.
When to use
- nginx fails to start with "Address already in use" on port 80 or 443
- After unclean shutdowns leave a listener behind
- Containers and host nginx fighting over the same port
When not to use
- Permission denied binding low ports (capability issue)
- Config syntax errors (different emerg message)
Tool compatibility
- nginx (
nginx -t,listendirective);ss -tlnp; systemd service management
Variant phrasings
nginx emerg bind failed 98
Error 98 is EADDRINUSE: find the process on the port with ss -tlnp and resolve the conflict.
two nginx instances port 80
Stop the stale one via the service manager; killing the master without cleanup leaves workers holding the port.
Why it happens
Only one process can bind a given address and port. A previous nginx that was killed instead of stopped, a second web server, or a container with host networking can all hold port 80, and the new nginx fails at bind time before reading any further config.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_i6jKFUvpywdwpovbGcewlA