Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

bind() to 0.0.0.0:80 failed (98: Address already in use): nginx or Apache will not start

Technical article
Troubleshooting

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

When nginx logs [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use), or Apache logs (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80, the web server asked the kernel for port 80 and was told another socket already holds it. Usually a second program, a second copy of the same server or a systemd socket unit owns the port; an overlapping Listen line in Apache's own configuration can cause the same error. Find the owner with ss -ltnp, then decide which program should have port 80.

What the error means

Only one program can listen on a given address and port at a time. A web server calls bind() when it starts, and the kernel refuses with EADDRINUSE. On Linux that is error number 98 ("Address already in use" in the errno(3) manual). The Apache documentation's own example shows (48)Address already in use: make_sock: could not bind to address [::]:80; 48 is the BSD number, and Linux prints 98.

nginx. In the 1.30.6 source, bind() to %V failed is logged at the emerg level. For EADDRINUSE nginx does not give up at once: it tries five times with a 500 ms pause after each failed attempt (5 x 500 ms = 2,500 ms in all), and the bind() ... failed line is logged on each of the five attempts, and logs a notice, try again to bind() after 500ms, before ending with still could not bind(). Any other error number stops the first attempt, so a (13: Permission denied) has a different cause.

Apache. In the 2.4.71 source the bind failure is message AH00072: make_sock: could not bind to address %pI. The server then logs no listening sockets available, shutting down, and AH00015: Unable to open logs follows in the startup sequence.

Address forms matter. 0.0.0.0:80 is IPv4 on every address; [::]:80 is the IPv6 wildcard. Apache's documentation explains that on Linux "the only way to handle both IPv6 and IPv4 is to use mapped addresses", so an Apache Listen 80 can occupy [::]:80 and with it IPv4 port 80, which then blocks nginx's 0.0.0.0:80. That follows from the documented behaviour; the documentation does not describe the clash itself. nginx's own ipv6only parameter "is turned on by default" for [::] listeners, so nginx separates the two.

Likely causes

Cause What you see How to confirm
A second web server (for example Apache and nginx both on port 80) One starts, the other fails with the error ss -ltnp lists the other program on port 80
A stale or manually started copy of the same server The service will not start, but the site is already answering The listed process is the same program, started outside the service manager
Another program on the port (a proxy, container publisher, application server) Error on start. The process name is not a web server Process name in the ss -p output
Duplicate or overlapping Listen lines in Apache Error appears at start and never works Apache documents that "Overlapping Listen directives will result in a fatal error"
IPv4 and IPv6 wildcard clash The message names [::]:80 or 0.0.0.0:80 The other listener is on the other wildcard, ss shows both forms
A systemd socket unit holds the port Port is listening although the service is stopped systemctl list-sockets shows a socket unit for port 80

Prove the cause before changing anything

1. Find who holds the port.

ss -ltnp '( sport = :80 )'

-l shows listening sockets, -t TCP, -n numeric ports and -p the "processes using sockets". The bracketed expression is the filter syntax used in the ss manual's own examples, such as ( sport = :http or sport = :https ). Run it as an administrator. The man page does not describe privilege requirements, so treat that as a precaution.

2. Check whether the holder is a socket unit.

systemctl list-sockets

The manual describes list-sockets as: "List socket units currently in memory, ordered by listening address." If a .socket unit listens on port 80, it holds the port and starts the service on demand. The systemd documentation says daemon software "configured for socket activation with socket units needs to be able" to receive the sockets from systemd. In that case a web server that opens its own port 80 conflicts with it.

3. Check the service state. systemctl status <unit> for each web server unit tells you which are running. Compare with the process in step 1.

4. Read the configuration for duplicates. For nginx, nginx -T prints the full configuration; search for every listen on port 80. For Apache, httpd -S shows the settings as parsed (currently only the virtual hosts); search the configuration files for Listen.

5. Do not rely on a configuration test to show a port conflict. In the nginx 1.30.6 source, during nginx -t the EADDRINUSE error is not logged and not counted as a failure. A passing test does not prove the port is free. Apache's apachectl configtest is a syntax test.

Fix

Disruptive step: every change below stops, starts or moves a service that may be serving traffic. Keep a copy of each configuration file and restore it, then start the service again, if the change does not work.

Decide which program should own port 80, then change the other. Do not kill a process only because it is listed.

Another service owns the port by design

Move one program to another port. For Apache behind nginx, for example, Listen 127.0.0.1:8080 limits it to one interface and port. For nginx, change the listen line.

Disruptive step: changing a port and restarting a web server interrupts traffic for that site, and any proxy rule pointing at the old port breaks. To back out, restore the previous file and start the service again.

Stale copy of the same server

Stop the service through the service manager. If an old process remains, identify it by the PID in the ss output and stop it with its ordinary stop command first. Only if it ignores the request should you consider forcing it.

Disruptive step: stopping a server drops its connections. Forcing a process to end may lose in-flight requests. There is no way back for those requests.

Duplicate Listen lines

Remove the duplicate. Apache also warns that after changing Listen so that it conflicts with the old configuration, "it is necessary to stop and then start the server": a graceful restart is not enough.

Socket unit holds the port

Either let the socket unit own the port and leave the service to be started by it, or stop using socket activation for that service. systemctl disable --now <name>.socket disables and stops it. The manual says disable "does not implicitly stop the units that are being disabled" and tells you to combine it with the --now switch if that is wanted.

Disruptive step: disabling a socket unit means that the service is no longer started on first connection. To back out, enable and start the socket unit again.

Example (illustrative): web01 has nginx for the site and Apache pulled in by another package. After a reboot nginx fails with [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) and the site shows Apache's default page. ss -ltnp '( sport = :80 )' lists the Apache process on *:80. The administrator keeps nginx on port 80, sets Apache to Listen 127.0.0.1:8080 (the application it serves is reached through an nginx proxy_pass http://127.0.0.1:8080;), saves a copy of the Apache file first, runs apachectl configtest, then stops and starts Apache so that the new Listen applies (a graceful restart is not enough). Next comes nginx -t, the nginx program's own check, and then starting nginx. The ss output now shows nginx on 80 and Apache on 8080.

Confirm the fix

  1. ss -ltnp '( sport = :80 )' shows only the intended program on port 80.
  2. The service stays running for at least a few minutes, and systemctl status shows no restart loop.
  3. A request from another machine returns the expected site, not the default page of the other server.
  4. The moved service answers on its new port, from the machines that need it.

What to watch afterwards

  • After package installs, check that a new web server did not enable itself. Installing a server package can start a second listener on port 80.
  • Keep a short list of which program owns each public port on each host.
  • Alert on a web server unit in a failed state, not only on site probes.
  • Container platforms that publish port 80 will cause the same error; check their published ports in the same way.

Risks and limits

  • These commands have not been run or lab-tested. They are taken from the nginx, Apache, systemd and Linux documentation and from the nginx and Apache source listed below.
  • Message wording is from nginx 1.30.6 and Apache 2.4.71. Other versions may differ.
  • ss needs enough privilege to show other users' processes; the manual does not say so, so check the output.
  • The Apache note about IPv4-mapped addresses depends on how it was built. The documentation says --enable-v4-mapped is the default on all platforms except FreeBSD, NetBSD and OpenBSD, so this is probably how your httpd was built.
  • Stopping the wrong service on a production host stops its users. Confirm the owner before stopping anything.

Sources