# 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.

Canonical: https://scaplet.com/errors/http/502/cloudflare

Guide Error · HTTP status codes

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

502 5xx · Server error

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?](#is-the-502-from-your-origin-or-from-cloudflare)
2. [How to get past a 502 as a visitor](#how-to-get-past-a-502-as-a-visitor)
3. [Fixes for a Cloudflare-sent (unbranded) 502](#fixes-for-a-cloudflare-sent-unbranded-502)
4. [502 behind Cloudflare Tunnel](#502-behind-cloudflare-tunnel)
5. [What to send Cloudflare Support](#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 with [ChatGPT](https://chatgpt.com/?hints=search&q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fhttp%2F502%2Fcloudflare%20(%22502%20Bad%20Gateway%20on%20Cloudflare%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Claude](https://claude.ai/new?q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fhttp%2F502%2Fcloudflare%20(%22502%20Bad%20Gateway%20on%20Cloudflare%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Perplexity](https://www.perplexity.ai/search?q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fhttp%2F502%2Fcloudflare%20(%22502%20Bad%20Gateway%20on%20Cloudflare%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [![Google](/logos/ai/google-color.svg)AI Mode](https://www.google.com/search?udm=50&q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fhttp%2F502%2Fcloudflare%20(%22502%20Bad%20Gateway%20on%20Cloudflare%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.)

_01_Reading 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](/errors/http/502) 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](/errors/cdn/cloudflare-504).

_02_How it works

## How to get past a 502 as a visitor

Cloudflare says that when most [5xx errors](/errors/http/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.

_03_Check 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](/glossary/gzip-compression) 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](/glossary/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'
```

_04_Tunnel 502 causes from Cloudflare's documentation

## 502 behind Cloudflare Tunnel

A 502 with the message `Unable to reach the origin service. The service may be down or it may not be responding to traffic from cloudflared` means the tunnel itself is connected to Cloudflare, but `cloudflared` cannot reach the origin service named in your ingress rule. Cloudflare contrasts this with error 1033, where the tunnel is not connected at all. Read the tunnel's error-level logs to find the cause.

Cause

### Origin service is not running

Log sign

`dial tcp [::1]:8080: connect: connection refused`

Fix

Start it; check with `curl -v http://localhost:8080` and `ss -tlnp`

Cause

### Wrong protocol in the service URL

Log sign

`malformed HTTP response` with TLS bytes

Fix

Match `http://` or `https://` to what the origin expects

Cause

### Wrong port

Log sign

Connection refused for that port

Fix

Compare the ingress port to the one the app listens on

Cause

### Certificate cannot be validated

Log sign

`x509: certificate is valid for example.com, not localhost`

Fix

Set `originServerName`, provide a CA with `caPool`, or use `noTLSVerify` only as a short-term measure

Ingress rule that fixes a name mismatch

```
ingress: - hostname: app.example.com service: https://localhost:443 originRequest: originServerName: app.example.com
```

_05_Explained

## 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](/errors/http/521), [522](/errors/http/522) and [524](/errors/http/524). A blocked request is a 403: see [403 Forbidden on Cloudflare](/errors/http/403/cloudflare).

_06_Explained

## 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](/seo-issues/server-errors-5xx) for how to trace the pattern and confirm recovery, and Google's documentation on how [HTTP status codes](/glossary/http-status-codes) affect its crawlers.

Questions

## Asked a lot.

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

_01_ How 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.

_02_ What 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.

_03_ Is 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.

_04_ Why 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. 01 [Error 502 or 504 - Cloudflare Support docs](https://developers.cloudflare.com/support/troubleshooting/http-status-codes/cloudflare-5xx-errors/error-502-504/) developers.cloudflare.com · checked 2026-10-25
2. 02 [Common tunnel errors - Cloudflare Tunnel docs](https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/troubleshoot-tunnels/common-errors/) developers.cloudflare.com · checked 2026-10-25
3. 03 [Cloudflare 5xx errors - Cloudflare Support docs](https://developers.cloudflare.com/support/troubleshooting/http-status-codes/cloudflare-5xx-errors/) developers.cloudflare.com · checked 2026-10-25
4. 04 [RFC 9110: HTTP Semantics](https://www.rfc-editor.org/rfc/rfc9110.html) rfc-editor.org · checked 2026-10-25
5. 05 [How HTTP status codes affect Google's crawlers](https://developers.google.com/crawling/docs/troubleshooting/http-status-codes) developers.google.com · checked 2026-10-25

## Keep learning

[All errors](/errors)

[Learn 502 Bad Gateway HTTP status codes](/errors/http/502) [Related 5xx server errors Status codes and links](/seo-issues/server-errors-5xx) [Read next 502 Bad Gateway in nginx HTTP status codes](/errors/http/502/nginx) [Do Run a free site audit Free, about two minutes](/site-audit)

Other 502 errors
[502 Bad Gateway in Apache](/errors/http/502/apache) [502 Bad Gateway in nginx](/errors/http/502/nginx) [502 Bad Gateway on Azure](/errors/http/502/azure) [AWS 502 Bad Gateway](/errors/cdn/aws-502-bad-gateway) [AWS Lambda 502 Bad Gateway](/errors/cdn/aws-lambda-502)

Nearby in errors
[503 Service Unavailable](/errors/http/503)

More in 502 Bad Gateway
[502 Bad Gateway in Apache](/errors/http/502/apache) [502 Bad Gateway in nginx](/errors/http/502/nginx) [502 Bad Gateway on Azure](/errors/http/502/azure) [502 Bad Gateway on Cloudflare](/errors/http/502/cloudflare)

Terms on this page
[Gzip compression](/glossary/gzip-compression) [HTTP/2](/glossary/http-2) [HTTP status codes](/glossary/http-status-codes)

Free · 2 minutes

## Tools point. Agencies advise. _This one ships._

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

[Audit my site free](/site-audit)

Free, no card 60 seconds Nobody will call you

- **46** fixes shipped without a ticket Brightpipe
- **0→7** ChatGPT citations in six weeks Paylane
