1. Log in to the Server

 

  1. Verify Nginx Service Status:    sudo systemctl status nginx

 

  1. Check Which Service is Listening on Port 80 :    sudo lsof -i :80

 

(Apache2 service was found to be running and occupying port 80, which conflicted with Nginx.)

 

  1. Disable Apache2 Service : 

   ( Stop and disable the Apache2 service to free up port 80)
 

sudo systemctl stop apache2

sudo systemctl disable apache2

 

  1. Enable and Verify Nginx on Port 80
      ( Ensure that Nginx is configured to listen on port 80 and restart the service)

sudo systemctl start nginx

sudo systemctl enable nginx

sudo systemctl restart nginx

 

  1. Verify that Nginx is now listening on port 80 : sudo lsof -i :80

 

  1. If the website still displays a 502 Bad Gateway error, check the Nginx error logs:

 

    /var/log/nginx/error.log

 

  1. If the logs indicated a PHP-related issue where the PHP-FPM service was stopped.

 

sudo systemctl start php-fpm

sudo systemctl enable php-fpm