502 Bad Gateway means a server acting as a gateway or proxy received an invalid response from the upstream server it contacted to fulfill the request. The proxy itself works; the problem lies behind it.
In typical setups, the proxy is nginx, Apache, a load balancer or a CDN, and the upstream is an application server such as PHP-FPM, Node.js, Gunicorn or a container. "Invalid response" covers a refused or reset connection, a crash in the middle of a response, malformed headers, or headers larger than the proxy's buffers (nginx logs "upstream sent too big header").
On Cloudflare, origin problems usually produce more specific codes such as 520, 521 or 522. A plain 502 seen through Cloudflare may come from the origin itself or from a problem inside Cloudflare's network.
Example response
HTTP/1.1 502 Bad Gateway
Date: Fri, 06 Nov 2026 10:15:32 GMT
Server: nginx
Content-Type: text/html
Content-Length: 142
Connection: keep-alive
<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx</center>
</body>
</html> SEO and redirect checking
Like other 5xx errors, short periods of 502s slow down crawling but do not remove pages, while persistent 502s lead to deindexing. 502s are often intermittent (a worker restarting, a pool running full), so check a URL several times or use the Bulk Redirect Checker to see how often it fails.
Common causes and use cases
- The application server (PHP-FPM, Node.js, Gunicorn) is down, restarting or has crashed.
- The proxy points to the wrong upstream address, port or socket.
- The upstream's response headers exceed the proxy's buffers (
proxy_buffer_sizeorfastcgi_buffer_sizein nginx). - A firewall or security group blocks the proxy from reaching the backend.