A 502 Bad Gateway error means a server in the middle (a CDN such as Cloudflare, or a proxy such as nginx) asked the server behind it for your page and got an invalid answer back. The fault is usually on the website’s side, not in your browser. To see which layer sent it, run curl -sS -o /dev/null -D - https://yoursite.com/ (on Windows: curl.exe and NUL) and read the Server line: cloudflare, nginx or hcdn (Hostinger CDN) tells you where to start.
I can’t break a real site, so the 502s below come from public test endpoints that return them on purpose (checked 26 November 2026).

Key takeaways
- A 502 is a proxy getting an invalid response from the server behind it (RFC 9110); a 504 is no timely response.
- The
Serverheader shows who answered. A Cloudflare-branded 502 page came from your origin server. - Common causes: PHP-FPM down, a plugin fatal error, a firewall blocking the CDN, wrong DNS, an overloaded plan.
- Google slows crawling on 5xx errors and eventually drops URLs that keep returning them.
Table of Contents
- 1What a 502 Bad Gateway Means
- 2502 vs 503 vs 504 vs Cloudflare 520-526
- 3Real Checks: What a 502 Looks Like
- 4How to Find Where the 502 Comes From
- Mac, Linux or Git Bash
- Windows PowerShell
- Read the answer
- 5How to Fix a 502 Bad Gateway by Cause
- PHP-FPM stopped or crashed
- A plugin or theme fatal error (WordPress)
- A firewall blocking your CDN
- DNS pointing at the wrong server
- Slow requests and timeouts
- Resource limits on shared hosting
- A 502 from the CDN itself
- 6Does a 502 Hurt SEO?
- 7Mistakes to Avoid
- What does 502 Bad Gateway mean?
- Is a 502 error my fault or the website’s?
- What is the difference between 502 and 504?
- How do I know if a 502 comes from Cloudflare or my server?
- How do I fix a 502 Bad Gateway in WordPress?
- Does a 502 error affect SEO?
What a 502 Bad Gateway Means
A request usually passes through a chain: browser, then a CDN or reverse proxy, then the web server, then the application (for WordPress, PHP running in PHP-FPM). RFC 9110, the HTTP standard, says a 502 means 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.”
The server showing the 502 is usually fine; the one behind it crashed, refused or closed the connection, or sent invalid HTTP. MDN says fixing it “probably requires investigation by server owners or administrators”.

502 vs 503 vs 504 vs Cloudflare 520-526
| Code | What it means | Defined by |
|---|---|---|
| 502 Bad Gateway | The proxy got an invalid response from the server behind it | RFC 9110 15.6.3 |
| 503 Service Unavailable | The server is overloaded or in maintenance; it may send Retry-After | RFC 9110 15.6.4 |
| 504 Gateway Timeout | The proxy got no timely response from the server behind it | RFC 9110 15.6.5 |
| 520 | Origin returned “an empty, unknown, or unexpected response” | Cloudflare |
| 521 | Origin “refuses connections from Cloudflare” | Cloudflare |
| 522 | Cloudflare “times out contacting the origin” (19 s for the TCP handshake, 90 s for data) | Cloudflare |
| 523 | Cloudflare “cannot contact your origin” (no route to its IP) | Cloudflare |
| 524 | Connected, but no HTTP response within the default 125-second Proxy Read Timeout | Cloudflare |
| 525 | SSL handshake between Cloudflare and the origin failed (Full or Full (Strict) mode) | Cloudflare |
| 526 | Cloudflare can’t validate the origin’s SSL certificate (Full (Strict) mode) | Cloudflare |
nginx’s source code (ngx_http_upstream.c) shows the 502/504 split: when nginx gives up on an upstream, a timeout becomes 504 and other connection failures fall to the default case, 502. So behind nginx, a slow PHP script usually shows 504 and a mid-request crash 502. Codes 520-526 are Cloudflare’s own, not the HTTP standard’s. For 500 errors, see the 500 Internal Server Error guide.
Real Checks: What a 502 Looks Like
On 26 November 2026 I ran these requests from my Windows 11 PC in India with curl 8.19.0 (Git Bash) and Windows’ curl.exe 8.23.0. The first four rows are test endpoints that return the code on purpose, not real outages.
| Request | Status | Server header |
|---|---|---|
| httpbin.org/status/502 (test endpoint) | 502 Bad Gateway | none sent |
| httpbin.org/status/503 and /504 | 503, 504 | not checked |
| www.cloudflare.com/cdn-cgi/error/502 (Cloudflare sample) | 502 Bad Gateway | cloudflare + CF-RAY |
| www.cloudflare.com/cdn-cgi/error/521 and /522 | 521, 522 | cloudflare + CF-RAY |
| harshilbarot.com | 200 OK | hcdn + x-hcdn-request-id |
| wordpress.org | 200 OK | nginx |
| www.cloudflare.com and example.com | 200 OK | cloudflare + CF-Ray |
| github.com | 200 OK | github.com |
| www.google.com | 200 OK | not checked |

httpbin’s 502 carried no Server header, so a missing header proves nothing. Cloudflare’s sample came back to curl as plain text, error code: 502, even when I asked for HTML. A second test service, httpstat.us, didn’t answer in three tries (curl errors 56 and 52): no answer at all is not a 502.
Windows PowerShell 5.1’s Invoke-WebRequest throws on a 502 (“The remote server returned an error: (502) Bad Gateway.”), so on Windows use curl.exe, which printed 502. (More methods: how to check an HTTP status code.)
How to Find Where the 502 Comes From
Mac, Linux or Git Bash
curl -sS -o /dev/null -w "%{http_code}\n" https://yoursite.com/
curl -sS -o /dev/null -D - https://yoursite.com/ | grep -iE "^(HTTP|server|cf-ray|x-hcdn)"
nslookup yoursite.comWindows PowerShell
curl.exe -sS -o NUL -w "%{http_code}" https://yoursite.com/
curl.exe -sS -o NUL -D - https://yoursite.com/ | findstr /i "HTTP/ server: cf-ray x-hcdn"
Resolve-DnsName yoursite.com -Type ALine one prints the status code, line two shows who answered (-S keeps curl’s errors visible), line three shows your domain’s IP addresses. I ran each form on 26 November (the first block in Git Bash on Windows; I didn’t test on a Mac or Linux machine). Line two sends a GET on purpose: curl -I sends HEAD, which servers can answer differently. Cloudflare’s sample error URL returned 502 to my GET but 404 to curl -I (both hosts, both shells).
Read the answer
- Server: cloudflare plus CF-RAY: Cloudflare answered. Its docs say a Cloudflare-branded 502 page means “the 502 or 504 came from your origin web server”; a 502 from Cloudflare itself is “a blank page without the Cloudflare branding”. Open the URL in a browser to see which; curl shows only text.
- Server: hcdn plus x-hcdn-request-id: Hostinger CDN delivered it (Hostinger’s help: that header means the request “was delivered through Hostinger CDN”).
- Server: nginx: nginx answered. Its built-in 502 page is just the title “502 Bad Gateway” and a footer naming nginx.
- No Server header: some servers send none; read the other headers.
ipconfig /flushdns, which “Flushes and resets the contents of the DNS client resolver cache” (Microsoft). If the site fails for everyone, only its owner or host can fix it.How to Fix a 502 Bad Gateway by Cause
Hostinger’s 502 tutorial says to “start with your error logs. Check for recent plugin or theme changes, CDN issues, and PHP timeouts.”
PHP-FPM stopped or crashed
If PHP-FPM is down or its workers die, nginx’s error log shows connect() failed or upstream prematurely closed connection (both strings are in nginx’s source). Hostinger says to check “that fastcgi_pass matches the PHP-FPM pool’s listen address or socket” and, “If PHP-FPM has stopped, check its logs for the cause before restarting it.”
php.net says pm.max_children “sets the limit on the number of simultaneous requests that will be served”, and request_terminate_timeout (default 0, off) is when “the worker process will be killed”; a killed worker typically closes the connection, which nginx answers with a 502. A full worker pool, by Hostinger’s account, more often brings “delays or timeouts”. After nginx edits, run nginx -t, then nginx -s reload (usually as root, or use your host’s restart option).
A plugin or theme fatal error (WordPress)
If the 502 began after an update, add this snippet from WordPress’s debugging docs to wp-config.php. It logs errors to wp-content/debug.log without showing them to visitors:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );Reload the failing page and look in debug.log for a fatal error naming a plugin or theme folder. Disable it (steps in the “There has been a critical error” guide) and turn debugging off afterwards. If PHP ran out of memory, raise the WordPress memory limit.
A firewall blocking your CDN
Hostinger’s 502 tutorial lists “Firewall restrictions”: “Security settings blocking communication between servers.” Behind Cloudflare, its docs file this cause under 520, 521 and 522 rather than 502: the 522 page calls blocked or rate-limited Cloudflare IPs the “most common cause” and says to allow all its IP ranges (listed at cloudflare.com/ips), and the 520 page lists “Firewalls or security plugins blocking Cloudflare IPs”.
DNS pointing at the wrong server
After a migration, your CDN may still send traffic to an old IP. Hostinger lists “DNS problems” among 502 causes; Cloudflare’s docs file a wrong origin IP under 522 and 523. Cloudflare lists an origin IP that “does not match the IP address currently provisioned to your origin web server” as a 522 cause, so compare your CDN’s DNS record with the IP your host shows. To test the origin directly, use curl’s --resolve (“a sort of /etc/hosts alternative”, says curl’s manual): curl -sS -o /dev/null -D - --resolve yoursite.com:443:ORIGIN_IP https://yoursite.com/. A 200 there but a 502 via the CDN points at the CDN-to-origin link.
Slow requests and timeouts
nginx’s proxy_read_timeout and fastcgi_read_timeout default to 60 seconds between reads, Cloudflare waits 125 seconds by default before a 524, and Apache’s ProxyTimeout defaults to its Timeout value. Raising timeouts hides the symptom; it’s better to find and fix the slow layer behind a high TTFB.
Resource limits on shared hosting
Hostinger’s tutorial says a 502 that “affects several pages during a traffic spike gives you a reason to check for resource limits”. Its help page says hitting the RAM or process limit may show “the 503 Service Unavailable error”, and a full PHP worker pool may cause “delays or timeouts”. On the plan’s Resources Usage page, check the CPU, Memory, Throughput (I/O) and PHP Workers charts for Faults (times a limit was reached) around the time of the error.
A 502 from the CDN itself
For an unbranded Cloudflare 502, its docs name an origin compression fault (gzip with a wrong content-length) and brief errors while traffic moves between data centers. Its 520 page offers a temporary workaround: set the record to DNS-only or pause Cloudflare.

After any fix, purge the CDN cache and retest logged out. If the page loops instead, see ERR_TOO_MANY_REDIRECTS; Hostinger CDN vs Cloudflare compares the two CDNs used here.
Does a 502 Hurt SEO?
Google’s HTTP status code docs say “5xx and 429 server errors prompt Google’s crawlers to temporarily slow down with crawling”, and already indexed URLs “are preserved in the index, but eventually dropped.” Once the server returns 2xx, “Google gradually increases the crawl rate”. It gives no time frame.
Mistakes to Avoid
- Blaming the CDN by default. A Cloudflare-branded 502 means your origin sent it.
- Raising every timeout. Fix the slow request.
- Restarting PHP-FPM without reading its log. The cause will come back.
- Testing only logged in. Check logged out with curl.

Checklist in text: confirm the code with curl; read the Server header; check whether the Cloudflare page is branded; read the web server, PHP-FPM and debug logs; check the firewall allows your CDN and DNS points at the right server; fix, purge caches and retest logged out.
What does 502 Bad Gateway mean?
A gateway or proxy, such as a CDN or nginx, got an invalid response from the server behind it (RFC 9110).
Is a 502 error my fault or the website’s?
Usually the website’s, unless it works for others and you use a VPN. Reload, try another network, flush DNS.
What is the difference between 502 and 504?
A 502 is an invalid response; a 504 is no timely response. In nginx, an upstream timeout becomes 504.
How do I know if a 502 comes from Cloudflare or my server?
A Cloudflare-branded 502 page came from your origin; an unbranded blank page came from Cloudflare. curl -sS -o /dev/null -D – https://yoursite.com/ shows Server: cloudflare and CF-RAY when Cloudflare answered.
How do I fix a 502 Bad Gateway in WordPress?
Turn on WP_DEBUG_LOG, reload, and disable the plugin or theme named in wp-content/debug.log. If it’s empty, check PHP-FPM and server logs.
Does a 502 error affect SEO?
Google slows crawling on 5xx errors and eventually drops indexed URLs that keep returning them.



