Skip to main content

502 Bad Gateway: every cause and how to fix it

TL;DR

nginx or your reverse proxy returned 502 because the upstream application did not respond correctly — diagnose PHP-FPM, Node, or proxy timeouts.

Key facts

Topic
Production error triage
Stack
Linux

TL;DR

A 502 Bad Gateway means your reverse proxy received an invalid response from an upstream application server — not that the internet is broken.

Common causes

  • PHP-FPM pool exhausted (pm.max_children reached)
  • Upstream process crashed or not listening on the expected socket/port
  • nginx fastcgi_pass pointing at a dead socket after deploy
  • Node/PM2 process down behind nginx

Manual fix workflow

sudo tail -n 50 /var/log/nginx/error.log
sudo systemctl status php8.3-fpm

Recycle workers safely, then confirm curl -I http://127.0.0.1 from the server.

How Reflex helps

Reflex correlates 502 spikes with FPM pool metrics, queue backlog, and deploy markers — then runs playbooks to restart services or roll back bad releases with an audit trail.