Free auditStart free
GuideError · HTTP status codes

502 Bad Gateway

A 502 Bad Gateway means a proxy or CDN got an invalid response from the server behind it. See who causes it, how visitors get past it, and how owners fix it.

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

A 502 Bad Gateway means a server acting as a gateway or proxy, such as nginx, a load balancer or a CDN, received an invalid response from the server behind it. The cause is usually on the site side, not yours. Visitors can retry; owners should check that the origin is running and answering the proxy correctly.

  1. What a 502 means and who causes it
  2. How to get past a 502 as a visitor
  3. How to find the cause as a site owner
  4. What it does to SEO
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
01Who usually causes a 502

What a 502 means and who causes it

RFC 9110 defines 502 as a status that "indicates that the server, while acting as a gateway or proxy, received an invalid response from an inbound server it accessed while attempting to fulfill the request." Two servers are involved. The one you talked to (the proxy, load balancer or CDN) is fine enough to answer. The one behind it (the origin, or "upstream") failed to give it a usable reply.
Layer

Origin server

Typical cause
The app or web server crashed, restarted, or is not listening where the proxy expects
Who can fix it
Site owner or host
Layer

Proxy or load balancer

Typical cause
Wrong upstream address, port or socket; response headers larger than the proxy buffer
Who can fix it
Site owner or host
Layer

CDN

Typical cause
Cannot connect to the origin, TLS mismatch with the origin, malformed compressed response
Who can fix it
Site owner, sometimes the CDN vendor
Layer

Visitor network

Typical cause
VPN, DNS, firewall or proxy settings; the site works for other people
Who can fix it
Visitor

MDN adds the distinction that matters when you debug. If the origin sends a valid HTTP error response, the gateway should pass that on instead of a 502. If the gateway gets no HTTP response at all within its time limit, it sends a 504 Gateway Timeout. So a 502 points at a reply that was broken, empty or refused, not a slow one.

02How it works

How to get past a 502 as a visitor

A 502 does not mean you were blocked. It describes a failure between two servers. A server that understood the request and refuses it sends 403 Forbidden instead, which RFC 9110 defines as "understood the request but refuses to fulfill it".

  1. 01

    Reload once or twice

    If the origin was restarting or overloaded, a reload can work. Wait a minute, then try again.

  2. 02

    Test another network or device

    MDN says fixing a 502 probably requires investigation by server owners or administrators, with client networking errors as the exception, particularly if the service works for other visitors and if clients use VPNs or other custom networking setups. Turn off the VPN or try mobile data.

  3. 03

    Check your own settings

    If only your connection fails, check network settings, firewall setup, proxy settings and DNS configuration, as MDN suggests.

  4. 04

    Contact the site

    If every device and network fails, the owner or host has to fix it. Tell them the time of the error and the exact URL.

03Common causes of a 502, where to look and the fix

How to find the cause as a site owner

Work from the origin outward. First test the origin directly, skipping the proxy and CDN. If it answers correctly, the fault is in the proxy configuration or the path between them. If it does not answer, the proxy is only reporting a real origin failure.
Cause

Origin process is down

Where to look
Process manager status, app logs, host memory
Fix
Restart it and fix the crash; add a health check so the load balancer stops sending traffic to a dead node
Cause

Wrong upstream address, port or socket

Where to look
Proxy config (for nginx, the proxy_pass or fastcgi_pass line)
Fix
Point it at the address the app really listens on
Cause

Origin response header larger than the buffer

Where to look
Proxy buffer settings
Fix
In nginx, raise proxy_buffer_size: the docs say a first response part over the buffer size "is considered invalid"
Cause

TLS to origin fails (CloudFront)

Where to look
Origin certificate names, expiry and chain
Fix
CloudFront returns 502 for an expired, invalid or self-signed origin certificate, a wrong-order chain, or a name that matches neither the Origin Domain nor the Host header
Cause

Origin refuses CloudFront on its ports

Where to look
Firewall and security rules for ports 80 and 443 by default
Fix
Allow the published CloudFront ranges and confirm the web server is running
Cause

Origin DNS fails (CloudFront)

Where to look
The NonS3OriginDnsError code
Fix
Fix the DNS records for the origin domain, then retest with dig from a public network
Cause

Compression mismatch (Cloudflare)

Where to look
Origin response headers
Fix
Cloudflare lists an origin that serves gzip-encoded content but does not update the content-length header as one cause of 502 and 504
Test the origin directly
# From the proxy host, hit the app on its own port
curl -sS -o /dev/null -w "%{http_code} %{time_total}s\n" http://127.0.0.1:8000/

# Through the public hostname, with response headers
curl -sSI https://example.com/ | head -n 20

If your proxy is nginx, the stack-specific checks (socket permissions, buffer sizes, PHP-FPM) are on 502 Bad Gateway in nginx. If the proxy got no HTTP response at all, you will see 504 Gateway Timeout instead.

Causes and fixes differ by server and platform. See the 502 guides for Apache, Cloudflare, nginx.

04Explained

What it does to SEO

Google treats 5xx responses as server errors: they make its crawlers temporarily slow down, content returned with them is ignored, and already indexed URLs are preserved but eventually dropped if the errors persist. Google says that once the server responds with a 2xx status code again, it gradually increases the crawl rate. See 5xx server errors for how to trace and verify 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.

01Is a 502 error my fault?

Rarely. A 502 is a gateway or proxy reporting that the server behind it gave an invalid response, so the fix is on the site owner or host side. The exception is your own network: MDN says VPNs, firewall, proxy and DNS settings can cause it when the site works for other people.

02What is the difference between 502 and 504?

A 502 means the gateway received an invalid response from the upstream server. A 504 means the gateway did not receive a response from it in time. In MDN's wording, with a 504 the proxy "did not receive any HTTP response from the origin within a certain time".

03How do I fix a 502 Bad Gateway on my own site?

Request the origin directly. If it fails, restart or repair the app. If it works, check the proxy or CDN: the upstream address, buffer sizes, TLS settings to the origin, firewall rules and DNS. Then retest through the public hostname.

04Does a 502 mean I am blocked?

No. A 502 describes a failure between two servers. A server that understood the request and refuses it responds with 403 Forbidden.

Sources · 6

Every fact, linked and dated.

Official docs first. The date is when we last opened each page.
  • rfc-editor.org
  • mozilla.org
  • google.com
  • cloudflare.com
  • amazon.com
  • nginx.org
  1. 01RFC 9110: HTTP Semanticsrfc-editor.org · checked 2026-10-25
  2. 02MDN: 502 Bad Gatewaydeveloper.mozilla.org · checked 2026-10-25
  3. 03How HTTP status codes affect Google's crawlersdevelopers.google.com · checked 2026-10-25
  4. 04Cloudflare: 502 and 504 errorsdevelopers.cloudflare.com · checked 2026-10-25
  5. 05Amazon CloudFront: HTTP 502 status code (Bad Gateway)docs.aws.amazon.com · checked 2026-10-25
  6. 06nginx: ngx_http_proxy_modulenginx.org · 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