# Nginx Start Failed: Address Already in Use

You try to start Nginx and it fails with an error about the address already being in use. Another process has claimed port 80 or 443, and Nginx can't bind to it. This is a common issue on new servers, development machines, and after installing conflicting software.

Understanding the Error

When Nginx starts, it needs to bind to the configured ports (typically 80 and 443). If another process is already listening on those ports, Nginx fails immediately.

Check the error:

```bash sudo systemctl start nginx # Job failed. See "systemctl status nginx" for details.

sudo systemctl status nginx ```

Typical output: `` Apr 04 12:00:00 server nginx[12345]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) Apr 04 12:00:00 server nginx[12345]: nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)

The error number 98 (EADDRINUSE) confirms another process owns that port.

Step 1: Identify the Conflicting Process

Find what's using the ports:

```bash # Using lsof sudo lsof -i :80 sudo lsof -i :443

# Using netstat sudo netstat -tlnp | grep -E ':80|:443'

# Using ss (modern replacement) sudo ss -tlnp | grep -E ':80|:443'

# Using fuser sudo fuser 80/tcp sudo fuser 443/tcp ```

Output shows the process ID and name: `` COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME apache2 1234 root 4u IPv6 12345 0t0 TCP *:80 (LISTEN) apache2 1234 root 6u IPv6 12346 0t0 TCP *:443 (LISTEN)

Common Cause 1: Apache Running on Same Ports

Apache is the most common conflict on new servers.

Check if Apache is running: ``bash sudo systemctl status apache2 # or sudo systemctl status httpd

Solution: Stop Apache: ```bash # Stop Apache sudo systemctl stop apache2 sudo systemctl disable apache2

# Then start Nginx sudo systemctl start nginx ```

Alternative: Configure Apache to use different ports:

Edit /etc/apache2/ports.conf: ``apache Listen 8080 Listen 8443

Update virtual hosts to use the new ports.

Common Cause 2: Another Nginx Instance

A rogue Nginx worker or master process may be running.

Check for Nginx processes: ``bash ps aux | grep nginx

Kill all Nginx processes: ``bash sudo pkill -9 nginx sudo systemctl start nginx

Or use the proper stop: ``bash sudo systemctl stop nginx # Wait a moment sudo systemctl start nginx

Common Cause 3: Development Servers

Node.js, Python, or other development servers running on port 80.

Find and identify: ``bash sudo lsof -i :80 | grep LISTEN

Output example: `` node 5678 user 22u IPv6 12345 0t0 TCP *:80 (LISTEN)

Solution: ```bash # Kill the specific process sudo kill 5678

# Or stop the service sudo systemctl stop mynodeapp ```

Common Cause 4: Docker Containers

Docker containers mapping to host ports.

Check Docker containers: ``bash sudo docker ps sudo docker ps --format "table {{.Names}}\t{{.Ports}}"

Look for port mappings like 0.0.0.0:80->80/tcp.

Solution: ```bash # Stop the conflicting container sudo docker stop container_name

# Or remove it sudo docker rm -f container_name ```

Prevent future conflicts:

Change the container port mapping: ``bash docker run -p 8080:80 nginx

Common Cause 5: systemd Socket Activation

Sometimes systemd holds sockets for services.

Check systemd sockets: ``bash sudo systemctl list-sockets | grep -E ':80|:443'

Solution: ```bash # Stop the socket sudo systemctl stop nginx.socket sudo systemctl stop apache2.socket

# Then start Nginx sudo systemctl start nginx ```

Common Cause 6: IPv4/IPv6 Binding Conflict

Nginx may fail if configured to bind to both IPv4 and IPv6 on the same port incorrectly.

Problematic config: ``nginx server { listen 80; listen [::]:80; # May conflict }

Solution: ```nginx # For IPv4 only server { listen 80; # Don't include IPv6 }

# For IPv6 only server { listen [::]:80; }

# For both (modern Nginx) server { listen 80; listen [::]:80 ipv6only=off; } ```

Or use dual-stack: ``nginx server { listen [::]:80 ipv6only=off; # Binds to both on some systems }

Common Cause 7: Multiple Listen Directives

Duplicate listen directives in different server blocks.

Check configuration: ``bash sudo nginx -T | grep "listen"

Look for duplicates: ```nginx # In file A server { listen 80; server_name site1.com; }

# In file B - same port, different server_name is fine server { listen 80; server_name site2.com; }

# But this causes conflict server { listen 80 default_server; # Two default_servers for same port server_name site3.com; } ```

Solution:

Only one default_server per port: ``nginx # In one config file server { listen 80 default_server; server_name _; }

Step 2: Kill the Conflicting Process

Once identified, remove the conflict:

```bash # Identify PID sudo lsof -i :80

# Kill gracefully sudo kill <PID>

# If it won't stop sudo kill -9 <PID>

# Or kill by process name sudo pkill apache2 ```

Step 3: Verify Port is Free

bash
sudo lsof -i :80
sudo lsof -i :443

Both should return nothing.

Step 4: Start Nginx

bash
sudo systemctl start nginx
sudo systemctl status nginx

Step 5: Prevent Future Conflicts

Disable conflicting services permanently: ``bash sudo systemctl disable apache2 sudo systemctl mask apache2 # Stronger - prevents manual start

Check what starts at boot: ``bash sudo systemctl list-unit-files | grep enabled | grep -E 'apache|nginx|httpd'

Using a Different Port (Alternative)

If you can't resolve the conflict, change Nginx's port:

nginx
server {
    listen 8080;
    server_name example.com;
}

Then use a reverse proxy or firewall redirect to map port 80 to 8080.

Quick Reference

Process Using PortHow to FindHow to Stop
Apachesystemctl status apache2systemctl stop apache2
Another Nginx`ps aux \grep nginx`pkill nginx
Node.js applsof -i :80kill <PID>
Docker containerdocker psdocker stop <name>
systemd socketsystemctl list-socketssystemctl stop <socket>

The key is identifying what's holding the port. Use lsof -i :80 or ss -tlnp, then stop or reconfigure that process before starting Nginx.