Hostxpeed
Login Get Started →
Troubleshooting

Fix Website "502 Bad Gateway"

5 min read
26 views
Jun 10, 2026

Understanding 502 Bad Gateway

This error indicates the upstream server (PHP-FPM, Node.js, etc.) isn't responding to Nginx/Apache.

Quick Diagnostics

# Check if PHP-FPM is running
sudo systemctl status php*-fpm

# Check Nginx status
sudo systemctl status nginx

# Check Apache status
sudo systemctl status apache2

Fix 1: Restart PHP-FPM

sudo systemctl restart php*-fpm

# Check which version
sudo systemctl list-units | grep php

Fix 2: Check PHP-FPM Pool

All children might be busy:

sudo netstat -anp | grep php-fpm | wc -l

Increase pm.max_children:

sudo nano /etc/php/*/fpm/pool.d/www.conf
# pm.max_children = 50 (increase from default)

Restart PHP-FPM.

Fix 3: Check Nginx Upstream Configuration

# Verify PHP socket
sudo nano /etc/nginx/sites-available/your-site
# Ensure this matches:
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
# Or
fastcgi_pass 127.0.0.1:9000;

Fix 4: Check Resource Limits

free -h
df -h
tail -f /var/log/php*-fpm.log

Fix 5: Increase Timeouts

In PHP-FPM pool:

request_terminate_timeout = 300
request_slowlog_timeout = 30

In Nginx:

proxy_read_timeout 300;
proxy_connect_timeout 300;

Fix 6: Check Nginx Error Log

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

Look for "connect() to unix:/var/run/php/php... failed".

Was this article helpful?