Skip to content

Glossary 502 error

What Is a 502 Error (Bad Gateway)?

  • Technical SEO
Definition

A 502 error (Bad Gateway) is the HTTP status code a server returns when it is acting as a gateway or proxy and gets an invalid response from the server behind it. MDN describes it as a generic catch-all for server errors that is specific to one point in the request chain. The fault lies between two servers, not in the visitor's browser.

A closed door in the foreground and, behind it on the right, a second, smaller door; the dotted path between them breaks off, and an orange lightning bolt sits in the gap, on a dark blue ground.
On this page 12
  1. Origin of the term
  2. How it works
  3. Types and variants
  4. Examples
  5. How to measure it
  6. Advantages and disadvantages
  7. How it differs from related concepts
  8. Criticism and limits
  9. How to apply it, step by step
  10. Best practices
  11. Common mistakes
  12. How this entry was made
In brief

502 error: a proxy or CDN got an invalid response from the origin server. How to tell which layer failed, and what Google does with the error.

A closed door in the foreground and, behind it on the right, a second, smaller door; the dotted path between them breaks off, and an orange lightning bolt sits in the gap, on a dark blue ground.

Origin of the term

The 502 has existed since the first HTTP/1.0 specification, RFC 1945, published in May 1996. Today it is defined in section 15.6.3 of RFC 9110, "HTTP Semantics", from June 2022, which replaces the earlier HTTP/1.1 documents.

Gateway and proxy are the two roles of the server in the middle: it takes the visitor's request, forwards it to another server, the origin, and passes back the answer. A CDN, a load balancer or a web server such as nginx in front of PHP all play that role. Each shows the 502 on its own error page, but the code is the same.

How it works

On a modern site, a request passes through several layers: the CDN, sometimes a load balancer, the web server and the application, which in turn queries the database. Each layer is a client of the next one. The 502 comes from the layer that was waiting for an answer and got something it cannot use: a dropped connection, or an empty or incomplete response.

Which layer was waiting, and which one did not answer?

The causes vendors describe, each in its own documentation:

  • The origin server has crashed, is overloaded or has a network failure, according to Cloudflare's page on 502 and 504 errors.
  • The application closes the connection before it answers. nginx logs this as "upstream prematurely closed connection". Maxim Dounin, an nginx developer, explained on the project's mailing list in 2012 that it usually comes from an upstream server crash or from a process killed by a limit on memory, CPU or execution time.
  • The gateway cannot find or reach the origin, for example because a custom DNS server does not resolve its name or a health probe fails. Microsoft describes this for Azure Application Gateway.
  • The origin sends broken compressed content or a wrong content length. According to Cloudflare, this produces a 502 generated by Cloudflare itself.

Types and variants

The wording of the error tells you little. What helps is knowing which layer produced it, and there are three clues.

The first is the response headers. The Server header names the software that answered, and Via, as defined in RFC 9110, records the intermediaries the message passed through. Cloudflare adds Cf-Ray, which identifies the data center that handled the request.

The second is the error page. Cloudflare documents that a 502 carrying its logo came from the origin server and was passed on, while a blank page without the logo was generated by Cloudflare.

The third is the web server log. If nginx records that the upstream closed the connection, the fault is in the application behind it, not in nginx.

Examples

A shop with Cloudflare in front and nginx with PHP on its server shows a 502 on every product page. The response carries Server: cloudflare and a Cf-Ray header, and the page shows the Cloudflare logo, so the error came from the origin. The nginx log shows "upstream prematurely closed connection" at the same minute, and the PHP log shows a process killed at its memory limit: the cause is in the application.

A second case: the same shop returns a blank 502 page with no logo. According to Cloudflare, its own network generated that response, and one possible cause is faulty compression at the origin.

How to measure it

In a terminal, curl -I https://www.example.com/ shows the status code and the Server, Via or Cf-Ray headers. To find out whether the problem sits in the CDN or at the origin, repeat the request directly against the origin server, bypassing the CDN.

In Google Search Console, the Page indexing report groups these errors under "Server error (5xx)". Occasional 502s are easier to spot in the Crawl Stats report, under host status: the server connectivity chart marks when the server did not respond or did not return a full response.

Advantages and disadvantages

Nobody picks a 502 the way they pick a 503 for maintenance: a 502 is a symptom. Its only advantage is diagnostic: the code already tells you the failure sits between two servers, and the headers narrow down which hop.

For SEO, Google treats it like any other server error. Its status code documentation gives 500, 502 and 503 the same effect: Google's crawlers slow down, the guide to reducing crawl rate adds that the slowdown applies to the whole hostname, and indexed URLs are kept, "but eventually dropped". For 502 it gives no deadline. What happens when a server error lasts for days is covered in the entry on the 503 error.

How it differs from related concepts

CodeWhat happensWho generates it
502 Bad GatewayThe gateway gets an invalid response from the originCDN, load balancer or web server in front of the application
504 Gateway TimeoutThe gateway gets no response in timeThe same intermediaries
520 to 526Cloudflare's own errors, such as an unknown response (520) or a refused connection (521)Cloudflare only; these are not standard codes

Source: RFC 9110 (June 2022), sections 15.6.3 and 15.6.5; Cloudflare, "Cloudflare 5xx errors", "Error 520" and "Error 521" (accessed 12.11.2026).

A 500 is a generic failure on the server itself, and a 503 says the server cannot handle requests right now because of overload or maintenance. For example, if the origin's firewall blocks Cloudflare's IP addresses, Cloudflare shows a 521 instead of a 502.

Criticism and limits

None of the sources consulted says which cause is the most common, so claims like "a 502 is almost always the host's fault" have nothing behind them. Cloudflare's documentation lists failures both at the origin and in its own network.

For 502 there is no published deadline either. Google does not say how many days of 502 errors it tolerates before dropping a URL; it writes that URLs are "eventually" dropped if the error persists. Only for 503 and 429 does its page on crawling errors speak of more than two days.

How to apply it, step by step

  • Use curl to check which headers come with the 502, and whether the page carries the CDN's logo.
  • Repeat the request against the origin, bypassing the CDN.
  • Search the web server log for the same time and the proxy's error message.
  • Check the application log for a process killed over memory, CPU or time.
  • Compare the proxy's timeout with how long the application takes; Microsoft lists an exceeded backend timeout among the causes of 502 errors in Azure Application Gateway.
  • Once it is fixed, check host status in Search Console's Crawl Stats report.
  • If you are only visiting the page: reload it after a few minutes.

Best practices

  • Log the web server and the application in the same time zone so the two logs can be matched.
  • If maintenance will take the origin down, return a deliberate 503 instead of letting the CDN show a 502.

Common mistakes

  • Looking for the fault in the CDN when its own error page says the error came from the origin.
  • Treating a 502 as a problem with the visitor's browser.
  • Assuming Google treats a 502 more leniently than a 500 or a 503.

How this entry was made

This entry was written in November 2026 with AI assistance. The facts come from RFC 1945 and RFC 9110, Google's documentation on status codes and crawl rate, Search Console Help, and documentation from MDN, Cloudflare, Microsoft and nginx. It was reviewed before publication and contains no client data.

Manuel Riveiro Rodriguez CEO & Digital Strategist

A technical audit covers this and everything else in one pass.

Request an audit

Frequently asked

Is a 502 error my fault?

Usually not: the failure sits between two servers of the site you are visiting. The exception MDN mentions: if the page works for other people, check your VPN, proxy or DNS settings.

Does a 502 error fix itself?

Sometimes, if the cause was a short overload or a restart of the origin server. If it persists, whoever runs the site has to check the origin and its logs.

What does "bad gateway" mean?

The gateway, the server in the middle, received a response from the server behind it that it cannot use.

Does a 502 error affect rankings?

If it is brief, it only affects crawling: Google slows down across the whole host and speeds up again once normal responses return. If it lasts, the affected URLs can drop out of the index.

What is the difference between a 502 and a 504?

With a 502, the gateway gets a response, but an invalid one. With a 504, it gets no response in time.

Sources

  1. IETF, RFC 9110 "HTTP Semantics", June 2022, sections 15.6.3 (502), 15.6.5 (504), 7.6.3 (Via) and 10.2.4 (Server).
  2. IETF, RFC 1945 "Hypertext Transfer Protocol -- HTTP/1.0", May 1996.
  3. Google, "How HTTP status codes affect Google's crawlers", last updated 4 February 2026.
  4. Google, "Reduce the Google crawl rate", last updated 6 October 2026.
  5. Search Console Help, "Crawl Stats report".
  6. MDN, "502 Bad Gateway", last modified 22 June 2026.
  7. Cloudflare, "Error 502 bad gateway or error 504 gateway timeout".
  8. Cloudflare, "Cloudflare 5xx errors", with the pages on errors 520 and 521.
  9. Cloudflare, "Cloudflare HTTP headers", Cf-Ray header.
  10. Microsoft, "Troubleshoot bad gateway (502) errors in Azure Application Gateway", last updated 16 September 2026.
  11. nginx mailing list, Maxim Dounin, "nginx upstream prematurely closed connection", 30 March 2012.
  12. Google Search Central, "Troubleshoot Google Search crawling errors", last updated 18 December 2025. Source for the more than two days of 503 or 429.