A Cloudflare 520 means the edge reached your server, sent the request, and got back something that is not a valid HTTP response — an empty reply, a connection reset mid-response, or headers too large for Cloudflare to accept. On a WordPress site the two causes that account for most incidents are PHP-FPM crashing while building the page and a plugin inflating cookies or response headers past Cloudflare’s limits. Check the origin error log at the timestamp of a failed request first; that alone identifies the cause more often than anything else.
What’s happening
The request path is browser → Cloudflare edge → your origin. A 520 tells you the last hop half-worked: the TCP connection and TLS handshake to the origin succeeded and the request went out, but what came back was unusable. Cloudflare’s 5xx troubleshooting documentation lists the concrete cases: the origin returned an empty response, the connection was reset (a TCP RST) after the request was accepted, the reply was not valid HTTP at all, or the response headers exceeded Cloudflare’s size limit — roughly 32 KB total, 16 KB for any single header. When any of those happen, the edge gives up and serves its branded 520 page with a Ray ID.
The important mental shift: Cloudflare is the messenger here, not the cause. Something on or in front of your origin produced garbage. The behaviour is identical on Free, Pro, and Business plans — there is no plan setting that changes 520 handling. On WordPress specifically, the usual producers of garbage are: a PHP-FPM worker segfaulting mid-request (broken extension, corrupted opcache, plugin conflict after an update), the kernel’s OOM killer terminating a worker, a session or A/B-testing plugin stuffing data into cookies until Set-Cookie headers blow past the limit, or a security layer (mod_security, a firewall appliance) resetting connections it dislikes.
What to check first
- Is it every page or specific URLs? 520 only on
/wp-admin/or checkout points at a heavy code path or oversized admin cookies; 520 everywhere points at a crashing PHP pool or a device in front of the server. - Origin error logs at the exact timestamp of a failed request — grab the time from the visitor or your monitoring, not “around then”.
- Incognito window test. If the site loads clean without cookies but 520s for logged-in users, you are in cookie/header-size territory.
- What changed recently? Plugin or theme update, PHP version switch, new security module. 520s almost never start spontaneously.
- cloudflarestatus.com — two minutes to rule out an edge incident before a two-hour origin hunt.
How to verify
Get the origin IP from the Cloudflare dashboard (DNS → Records — the record content, since public DNS returns edge IPs for proxied names), then test the origin directly:
# Request the failing page straight from the origin, bypassing Cloudflare
curl -sv --resolve example.com:443:203.0.113.10 https://example.com/ -o /dev/null
# Same test on a failing URL, showing response headers
curl -s -D - --resolve example.com:443:203.0.113.10 https://example.com/wp-admin/ -o /dev/null
# How big are the response headers? Anything approaching 16 KB is suspect
curl -s -D - --resolve example.com:443:203.0.113.10 https://example.com/ -o /dev/null | wc -c
An empty reply, connection reset by peer, or a header dump measured in tens of kilobytes reproduces the 520 outside Cloudflare — the problem is now local and debuggable. Then read the logs:
# PHP-FPM crashes show up as SIGSEGV or "exited on signal"
grep -E "SIGSEGV|exited on signal|child .* exited" /var/log/php*-fpm.log | tail -20
# Web server errors in the incident window
tail -50 /var/log/nginx/error.log
tail -50 /var/log/apache2/error.log
# Did the kernel kill a worker?
dmesg -T | grep -i "out of memory" | tail -10
# WordPress-level fatals, if WP_DEBUG_LOG is enabled
tail -30 /var/www/example.com/wp-content/debug.log
The fix
- PHP-FPM is crashing —
SIGSEGVorexited on signal 11in the FPM log at incident timestamps. Disable the most recently updated plugin or PHP extension, restart PHP-FPM, and clear the opcache (systemctl restart php8.2-fpmcovers both). If crashes started after a PHP minor upgrade, roll the site’s pool back one version while you isolate the incompatible code. - Cookie or header bloat — the header dump from
curl -D -is huge, usually dozens ofSet-Cookielines from a session, cart, or A/B-testing plugin. Configure the plugin to store state server-side, or drop it. Keep total response headers well under 32 KB. - OOM killer terminating workers —
dmesgshowsOut of memory: Killed process (php-fpm). Lowerpm.max_childrenso the pool fits in RAM, or add memory. A pool sized for more workers than the box can hold crashes precisely at traffic peaks, which is why the 520s look random. - A security layer resetting connections —
mod_securityor a host firewall is dropping mid-response. Check the audit log (/var/log/modsec_audit.log) and disable the specific rule, not the engine. Also make sure the origin sees real visitor IPs rather than Cloudflare’s — restoring the client IP behind Cloudflare stops security tooling from reacting to edge IPs. - Non-HTTP output before headers — stray whitespace in
wp-config.phpor a fatal error printed before headers can make the response start with something other thanHTTP/. Re-save permalinks to regenerate.htaccess, and check for BOM characters or blank lines at the top of recently edited PHP files.
When this fix is wrong
If curl --resolve against the origin is clean every single time while 520s keep appearing through Cloudflare, stop debugging WordPress. Suspect something between the edge and the application: a load balancer or NAT device resetting reused connections, or a keepalive mismatch where the origin closes idle connections the edge is about to reuse. And a burst of 520s that lines up exactly with traffic peaks is a capacity problem, not a configuration one.
Common mistakes
- Purging the Cloudflare cache. A 520 is generated per-request on the origin fetch; the cache is not involved and the purge just adds load.
- Switching the DNS record to grey-cloud (DNS-only) and declaring victory — the crash is still there, you have only removed the messenger and exposed the origin IP. See DNS-only vs proxied for what that toggle actually changes.
- Blaming Cloudflare while the PHP-FPM log shows a segfault at every incident timestamp.
- Testing with an
/etc/hostsoverride, forgetting to remove it, and reading “site fixed” from a browser that is quietly bypassing Cloudflare.
Prevention
- Alert on
exited on signallines in the PHP-FPM log — crashes precede visible 520s. - Audit response headers after installing any plugin that touches sessions, carts, or testing; keep a header-size budget.
- Stage plugin and PHP updates somewhere that is not production.
- Watch origin memory headroom and tune
pm.max_childrento fit it. - Keep the
curl --resolvebypass one-liner in your runbook so the next 520 takes five minutes to localize, not an hour.
A 520 on WordPress is almost always the origin misbehaving, and the log evidence is usually one grep away. If the error keeps coming back, the problem usually sits between Cloudflare and the origin — Stack Harbor operates that whole path under Managed Cloud Ops, and you can book an infrastructure review.