A 502 Bad Gateway error indicates that the server, while acting as a gateway or proxy, received an invalid response from an inbound server it accessed while attempting to fulfill the request.
In modern web hosting, edge servers or reverse proxies (like Cloudflare, nginx, or AWS load balancers) sit in front of application backends (like Node.js, PHP-FPM, Python, or Ruby). When the backend crashes, drops the connection prematurely, or returns corrupt headers, the edge proxy returns a 502 error to the user.
Determining why
- The backend application server crashed or ran out of memory.
- PHP-FPM, Node.js, or your application daemon stopped running.
- A firewall or network misconfiguration between the proxy and backend dropped the connection.
Steps you could possibly take:
- Reload the page - Press F5 or Command-R to reload. If the backend process was briefly restarting, it may answer on the next try.
- Clear your browser cache - Occasionally a 502 response is cached by your browser or an intermediate proxy.
- If you are the website owner or server administrator:
- Check if your application process (e.g.
systemctl status php-fpmorpm2 status) is running. - Inspect your server error logs (such as
/var/log/nginx/error.log) for upstream connection refused or premature termination errors. - Ensure your origin server’s firewall permits incoming traffic from your reverse proxy or CDN IP addresses.
- Check if your application process (e.g.