Skip to content

502 Bad Gateway Error ​

A 502 Bad Gateway error appears when the web server (Nginx or Apache) does not get a valid response from the program running behind the website, such as PHP-FPM or a Node.js or Python application. The web server itself is still running, but the application behind it has stopped, is overloaded, or responds too slowly.

Common causes ​

  • PHP-FPM or the application (Node.js, Python…) has stopped or keeps restarting.
  • The server has run out of RAM, the CPU is overloaded, or the disk is full.
  • A request takes too long to process and exceeds the timeout.
  • The application runs on a different port than the website expects, or a firewall blocks the connection to a backend server.

Check with FlashPanel ​

Go through the following steps in order. In most cases you can find the cause without using the command line.

1. View the website's error log ​

  1. Open the website in FlashPanel.
  2. In the website menu, select Nginx (or Apache) > Error Log.
  3. Look for error lines that match the time the 502 error occurred. Common messages:
    • Connection refused or No such file or directory: PHP-FPM or the application is not running, or runs on the wrong port.
    • upstream timed out: the application takes too long to respond (see step 4).
    • no live upstreams: none of the backend servers in Load Balancing respond.

2. Check PHP-FPM ​

Applies to PHP websites (WordPress, Laravel…).

  1. Open the website's Overview page and check the version on the PHP line.
  2. Open the server and select the Apps menu.
  3. Find the PHP application with the matching version and check the status label next to its name:
    • Active (green): the application is running.
    • Inactive (red): the application has stopped.
  4. If the application has stopped, click Start or Restart in the action column (hover over the icons to see the button names), then reload the website.
  5. If the application keeps stopping, click Log to see the errors. You can enable Auto Restart so the application starts again automatically when it stops unexpectedly. See Applications.

You can use the same page to check Nginx, Apache, MySQL/MariaDB, and any other application the website relies on.

3. Check Node.js, Python, or background processes ​

If the website forwards traffic to an application running on a port, check that process wherever you started it:

  • PM2: view the process status, restart it, and read its logs. See PM2.
  • Supervisor: check that the program is still running and read its log file. See Supervisor.
  • Service: view the status of and restart systemd services. See Service.

Make sure the application listens on the same port the website forwards traffic to.

4. Check resources and timeouts ​

  • Open the server's Home page and turn on the switch on the Server Informations card to watch live CPU and RAM usage and the Load average. If RAM or CPU usage stays high, upgrade the server or reduce the load.
  • If the disk is full, use the Cleanup System utility on the server's Home page. See Cleanup System.
  • If the error happens on long-running tasks (data imports, report exports…), increase Max Execution Time on the server's PHP page. This setting also adjusts the matching Nginx timeout. See PHP.

Check from the command line ​

If the steps above don't reveal the cause, open Terminal from the website's Overview page or connect to the server over SSH, then run the commands below. Replace 8.3 with the website's PHP version and domain.com with your domain.

PHP-FPM

bash
sudo systemctl status php8.3-fpm
sudo systemctl restart php8.3-fpm

Nginx

bash
# Check that the configuration is valid
sudo nginx -t

# View the website's error log
sudo tail -n 100 /var/log/nginx/domain.com-error.log

Node.js applications with PM2

bash
pm2 list
pm2 logs --lines 100

System resources and listening ports

bash
free -h            # RAM
df -h              # Disk space
top                # Processes using the most CPU/RAM
sudo ss -tulpn     # Listening ports

Laravel applications

bash
tail -n 100 /home/flashpanel/domain.com/storage/logs/laravel.log

Quick checklist ​

  1. Check the website's Error Log.
  2. Check that PHP-FPM or the application is Active.
  3. Check the process in PM2, Supervisor, or Service (for Node.js and Python applications).
  4. Check CPU, RAM, and disk space.
  5. Increase Max Execution Time if the error happens on long-running tasks.
  6. Restart the related application and reload the website.