"502 Bad Gateway" on your website: what it means and how to fix it

A 502 means the front server answered, but the program behind it did not. The web server (often nginx, Cloudflare or your host's proxy) asked your site's app for the page and got nothing useful back. Your files are usually fine. Something stopped running.

What to do, in order

  1. Wait two minutes and reload. A restart or a deploy can cause a short 502. If it clears, check your host's status page for an incident.
  2. If you use Cloudflare, see whose error it is. A Cloudflare-branded 502 page means Cloudflare could not reach your host. Pause Cloudflare for the domain and load the site directly. If it still fails, the problem is at your host.
  3. Restart the app. On a VPS: sudo systemctl restart php8.2-fpm (or your PHP version), or restart your Node or Python service. On shared hosting, open a ticket and ask them to check PHP-FPM.
  4. Read the error log. On nginx, sudo tail -50 /var/log/nginx/error.log. "Connection refused" means the app is not running. "upstream timed out" means it is too slow. "upstream sent too big header" means a buffer setting is too small.
  5. On WordPress, suspect the last plugin. If the 502 started after an update, rename wp-content/plugins to plugins-off over FTP. If the site comes back, rename it back and turn plugins on one by one.
  6. Check memory. A server that runs out of memory kills the app. Run free -m. If free memory is near zero, add swap or a bigger plan.

Check it yourself

Run curl -sI https://yourdomain.com. The first line shows the status. A server: line saying cloudflare tells you the error passed through Cloudflare.


Want the rest of your site checked after it is back? Run a free 40-point check at tinkeraudit.com.