Nginx Fails to Start Due to Ports Already in Use (WP2)

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:

  1. 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"
  1. 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
  1. Kill any leftover processes manually:

sudo fuser -k 80/tcp
sudo fuser -k 443/tcp
  1. Restart Nginx:

sudo systemctl start nginx
sudo systemctl status nginx
  1. 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
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to Check if a Server Runs cPanel & WHM or WP Squared

Steps Open the server terminal. Run this command: readlink...

Installing cPanel on Servers with Less Than 2 GB RAM

Overview:cPanel & WHM is a popular web hosting control panel that usually requires a minimum...