HTTP 502 Bad Gateway — Meaning, Causes & How to Fix
The server, acting as a gateway or proxy, received an invalid response from the upstream server.
- Code
- 502
- Name
- Bad Gateway
- Class
- 5xx Server Error
- Specification
- RFC 9110 §15.6.3
- Cacheable by default
- Only with explicit Cache-Control / Expires
What HTTP 502 means
502 Bad Gateway is returned by a proxy, load balancer or CDN when the server behind it (the upstream) sent an invalid response — or, very often, refused or dropped the connection. The proxy itself is fine; the app behind it is not.
Common causes
- The application server (PHP-FPM, Node, Gunicorn) crashed or is not running.
- The upstream closed the connection or returned malformed headers.
- Wrong upstream address or port in the proxy config.
- A CDN like Cloudflare cannot reach the origin.
How to fix it
For site owners
- Check that the upstream service is running and listening on the configured port/socket.
- Read the proxy error log (e.g. nginx “upstream prematurely closed connection”).
- Increase upstream buffer sizes if headers are large.
For visitors & developers
- Reload after a moment; 502s are often brief during restarts or deploys.
SEO impact
Like all 5xx errors, frequent 502s make Googlebot crawl less, and URLs that keep failing can be dropped. Brief 502s during a deploy are not a problem.
Example 502 response
HTTP/1.1 502 Bad Gateway
Server: nginx
Content-Type: text/html
Related status codes
Check or look up another code
Search and filter every code in the HTTP Status Codes tool, browse the full list by class, or read HTTP status codes explained: the complete developer guide.
Open HTTP Status Codes tool →All status codesFrequently asked questions
What does HTTP 502 mean?
HTTP 502 Bad Gateway is a 5xx Server Error status code. The server, acting as a gateway or proxy, received an invalid response from the upstream server.
What is the difference between 502 and 504?
502: the upstream gave a bad or no valid response (often a crash or refused connection). 504: the upstream did not answer in time.
Is a 502 caused by my internet connection?
Almost never. It is between servers on the site’s side.
Which specification defines 502?
It is defined in RFC 9110 §15.6.3.
Is a 502 response cacheable?
Not by default. A 502 response is only stored by caches when it carries explicit freshness information such as Cache-Control: max-age or Expires.