# Nginx - Nginx: [Emerg] Bind() to [::]:80 Failed (98: Address Already in Use)

The error `nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)` indicates that Nginx is unable to start because another process is already using port 80 on the IPv6 address `[::]`. This can happen if another service is bound to the same port or if there’s a configuration issue. Here’s a step-by-step guide to troubleshoot and resolve this issue:

### **1. Identify the Conflicting Process**

Determine which process is using port 80.

### **On Linux:**

1. **Check Listening Ports:**
    
    Use `netstat` or `ss` to find the process listening on port 80.
    
    ```bash
    sudo netstat -tuln | grep :80
    ```
    
    Or with `ss`:
    
    ```bash
    sudo ss -tuln | grep :80
    ```
    
    This command shows the process and the address it’s bound to.
    
2. **Find the Process:**
    
    Once you identify that port 80 is in use, find the process using it:
    
    ```bash
    sudo lsof -i :80
    ```
    
    Or:
    
    ```bash
    sudo fuser -v 80/tcp
    ```
    
    These commands will list the processes using port 80.
    
3. **Kill or Reconfigure the Conflicting Process:**
    
    If another service (e.g., Apache, another instance of Nginx) is using port 80, you may need to stop it:
    
    ```bash
    sudo systemctl stop apache2    # Example for Apache
    sudo systemctl stop nginx      # Example for Nginx if it's another instance
    ```
    
    Alternatively, reconfigure the conflicting service to use a different port.
    

### **2. Check Nginx Configuration**

Ensure that there are no conflicting Nginx configuration files or duplicate server blocks.

### **Steps:**

1. **Check Nginx Configuration Files:**
    
    Look through your Nginx configuration files to ensure there are no duplicate server blocks attempting to bind to the same port.
    
    ```bash
    sudo grep -R "listen 80" /etc/nginx/
    ```
    
    This will help you identify if there are multiple configurations binding to port 80.
    
2. **Validate Nginx Configuration:**
    
    Use the following command to test the Nginx configuration for syntax errors or other issues:
    
    ```bash
    sudo nginx -t
    ```
    
    This command will check the configuration files and report any errors.
    

### **3. Restart Nginx**

After resolving any conflicts or configuration issues, restart Nginx.

```bash
sudo systemctl restart nginx
```

Or, if you're using older init scripts:

```bash
sudo service nginx restart
```

### **4. Review Logs**

Check Nginx’s error log for more details if the issue persists.

```bash
sudo tail -f /var/log/nginx/error.log
```

### **5. Handle IPv6 Bindings**

If you only need Nginx to listen on IPv4, you can modify your configuration to only bind to IPv4 addresses.

### **Example Configuration:**

```
server {
    listen 80;   # This listens on IPv4
    listen [::]:80 ipv6only=off;  # This listens on IPv6
    server_name example.com;
    root /var/www/html;
}
```

If you only need IPv4, you can remove or comment out the `listen [::]:80` directive.

### **Summary**

- **Identify Conflicting Process**: Use `netstat`, `ss`, `lsof`, or `fuser` to find which process is using port 80.
- **Check and Fix Configuration**: Ensure Nginx configurations are correct and do not conflict.
- **Restart Nginx**: Apply changes and restart Nginx.
- **Review Logs**: Check error logs for additional details.
- **IPv6 Considerations**: Adjust configuration if only IPv4 is needed.

By following these steps, you should be able to resolve the issue and start Nginx without the port conflict error.