Issue:
When attempting to start Nginx on a WPSquared (WP2) server, the service fails with the following error:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
Even though the Nginx configuration syntax passes (nginx -t), Nginx cannot start. This occurs because another process is already using the default HTTP (80) or HTTPS (443) ports.
Cause:
-
Another web server (e.g., Apache/httpd) is running.
-
A leftover Nginx process did not shut down properly.
-
Some other application is listening on ports 80 or 443.
Solution:
-
Check which process is using the ports:
sudo lsof -i :80
sudo lsof -i :443
# Or using netstat
sudo netstat -tulpn | grep -E "80|443"
-
Stop the conflicting service (if safe to do so):
sudo systemctl stop httpd # if Apache is running
sudo systemctl stop nginx # if a ghost Nginx process exists
-
Kill any leftover processes manually:
sudo fuser -k 80/tcp
sudo fuser -k 443/tcp
-
Restart Nginx:
sudo systemctl start nginx
sudo systemctl status nginx
-
Verify Nginx is running:
sudo systemctl status nginx
Prevention:
-
Ensure only one web server is running on the system.
-
Regularly check for leftover Nginx processes after updates or restarts.
-
Consider enabling Nginx to start automatically on boot if used as the primary web server:
sudo systemctl enable nginx
