Free auditStart free
GuideError · HTTP status codes

502 Bad Gateway on Cloudflare

A Cloudflare 502 comes from your origin or from Cloudflare itself. Tell them apart by the error page, then fix gzip, Tunnel, HTTP/2 and port issues.

5 min
read
5
sources
Oct 23, 2026
updated
Scaplet Editorial Team
author
The short answer

A 502 on a Cloudflare site comes from one of two places. A Cloudflare-branded 502 means your origin web server sent that status, so fix the origin. A blank, unbranded 502 came from Cloudflare, for example from a compression problem at the origin or a traffic shift between data centers. Tunnel setups add a third cause: cloudflared cannot reach the local service.

  1. Is the 502 from your origin or from Cloudflare?
  2. How to get past a 502 as a visitor
  3. Fixes for a Cloudflare-sent (unbranded) 502
  4. 502 behind Cloudflare Tunnel
  5. What to send Cloudflare Support
30-second check

Where does your site stand?

Four quick questions, then a straight answer.

1/4Have you checked your own site for this?
Summarize this page withChatGPTClaudePerplexityGoogleAI Mode
01Reading a Cloudflare 502

Is the 502 from your origin or from Cloudflare?

502 Bad Gateway is a standard status (RFC 9110, which the general 502 Bad Gateway page explains). What is specific to Cloudflare is who sent it. Cloudflare's documentation says 502 and 504 errors have two possible causes: your origin web server (most common) or Cloudflare itself. The error page tells you which.
What you see

Cloudflare-branded 502 page

Where it came from
Your origin web server responded with a standard 502
Start here
Origin: confirm it answers for the hostname and domain in the visitor's URL; look at load, crashes, network failures and timed out or blocked services
What you see

Blank page, no Cloudflare branding

Where it came from
Cloudflare
Start here
Compression at the origin, then a data center traffic shift (below)
What you see

502 with Unable to reach the origin service on a Tunnel route

Where it came from
cloudflared cannot reach the local service
Start here
Tunnel logs and the ingress rule (below)

Cloudflare notes that Custom Errors can change the appearance of its default error pages, so a restyled page may not look like these examples. For the 504 side of the same page, see Cloudflare 504.

02How it works

How to get past a 502 as a visitor

Cloudflare says that when most 5xx errors appear, the right first step is to contact the hosting provider or site administrator, and that Cloudflare Support only assists the domain owner. As a visitor you can do little beyond waiting and ruling out your own setup.
  1. 1

    Reload after a minute

    Cloudflare says a data center that suddenly gets more traffic can shift traffic to another one, and some clients may see temporary latency or 502s while that happens. A reload may clear it.

  2. 2

    Try another network or device

    If the page loads on mobile data or on someone else's connection, the problem is local. If it fails everywhere, the site has the fault.

  3. 3

    Tell the site owner

    Send the exact URL, the time with your timezone and the error code. Cloudflare lists those details for owners to give a hosting provider. Add the Ray ID if the error page shows one, since Cloudflare's log tools can filter by it.

03Check it

Fixes for a Cloudflare-sent (unbranded) 502

Cloudflare names two causes of an unbranded 502 or 504. The first is a compression issue at the origin: the origin serves gzip-encoded content but does not update the content-length header, or serves broken gzip content. To test it, disable compression at the origin and see whether the error goes away. The second is a data center traffic shift, which Cloudflare says normally finishes in a few seconds.

Two further Cloudflare-side causes are listed. Using Cloudflare Gateway can lead to a 502 if the origin only partially supports HTTP/2. If you use Dedicated CDN Egress IPs, Cloudflare can temporarily run out of source ports: each such IP supports up to 40,000 concurrent connections per origin IP port, so heavy concurrent traffic to one origin can cause intermittent 502s even when the origin is healthy. Cloudflare says to contact your account team in that case.

Check what the origin sends for gzip
# Compare the declared length with the bytes you actually receive
curl -s -D - -o /tmp/body.gz -H 'Accept-Encoding: gzip' https://ORIGIN_IP/ -H 'Host: example.com' -k | grep -i -E 'content-(length|encoding)'
wc -c /tmp/body.gz
gzip -t /tmp/body.gz && echo 'gzip body is valid'
05Explained

What to send Cloudflare Support

Cloudflare asks for the timestamp with timezone, the URL that returned the 502 or 504, and the output of browsing to <YOUR_DOMAIN>/cdn-cgi/trace. Cloudflare's 5xx guidance adds that the cause is not always in the origin's error logs, so check load balancers, caches, proxies and firewalls between Cloudflare and the origin too.

A 502 that Cloudflare sends is different from a Cloudflare-specific 52x. Those are listed on 521, 522 and 524. A blocked request is a 403: see 403 Forbidden on Cloudflare.

06Explained

What it does to SEO

Google treats 5xx responses as server errors: its crawlers slow down, content returned with them is ignored, and URLs already indexed are kept for a while but eventually dropped if the errors persist. Cloudflare serves the 502 to crawlers, so repeated 502s slow crawling. See 5xx server errors for how to trace the pattern and confirm recovery, and Google's documentation on how HTTP status codes affect its crawlers.
Questions

Asked a lot.

4 questions people ask next, answered from the sources on this page.

01How do I fix a 502 Bad Gateway on Cloudflare?

Check the error page. If it is Cloudflare-branded, fix your origin. If it is blank and unbranded, test disabling compression at the origin. For Tunnel setups, read the cloudflared logs and check the service URL, port and certificate.

02What does a 502 Bad Gateway mean on Cloudflare?

Cloudflare says it is unable to establish contact with your origin web server, either because the origin returned a 502 or 504, or because Cloudflare itself produced one.

03Is the 502 my fault as a visitor?

Usually not. Cloudflare tells visitors to report 5xx problems to the site owner. Try another network, and reload after a minute.

04Why do I get a 502 only on a Cloudflare Tunnel site?

The tunnel is connected, but cloudflared cannot reach the local service in your ingress rule: it is down, the protocol or port is wrong, or its certificate cannot be validated.

Sources · 5

Every fact, linked and dated.

Official docs first. The date is when we last opened each page.
  • cloudflare.com
  • rfc-editor.org
  • google.com
  1. 01Error 502 or 504 - Cloudflare Support docsdevelopers.cloudflare.com · checked 2026-10-25
  2. 02Common tunnel errors - Cloudflare Tunnel docsdevelopers.cloudflare.com · checked 2026-10-25
  3. 03Cloudflare 5xx errors - Cloudflare Support docsdevelopers.cloudflare.com · checked 2026-10-25
  4. 04RFC 9110: HTTP Semanticsrfc-editor.org · checked 2026-10-25
  5. 05How HTTP status codes affect Google's crawlersdevelopers.google.com · checked 2026-10-25
Free · 2 minutes

Tools point. Agencies advise. This one ships.

Run the free audit, then approve the fixes. Every change can be undone.

Free, no card60 secondsNobody will call you
  • 46 fixes shipped without a ticket Brightpipe
  • 0→7 ChatGPT citations in six weeks Paylane