Troubleshooting guide
Cloudflare error 520: web server returns an unknown error
A 520 means Cloudflare reached your server, but what came back was empty, malformed or cut off. Cloudflare cannot tell you more, so the answer is in your origin's logs.
5 min read10 sectionsUpdated
On this page
Key points
- 520 is a catch-all: the origin connected but its response was empty, invalid or reset.
- The fix is almost always on the origin, not at Cloudflare.
- Start with the origin's error log at the exact time of the error, matched by the CF-Ray ID.
- Common causes: the application crashed mid-request, response headers too large, a firewall resetting connections, keep-alive timeouts that close reused connections.
What error 520 means
When Cloudflare proxies a request it opens a connection to your server (the origin), sends the request and waits for an HTTP response. Error 520 means the connection worked, but the response was not a valid HTTP response Cloudflare could pass on. The other 52x codes describe more specific failures; 520 is what you get when none of them fits.
| Error | What Cloudflare saw | Where to look first |
|---|---|---|
| 520 | A connection, then an empty, invalid or reset response | Origin application and web server error logs |
| 521 | The origin actively refused the TCP connection | Is the web server running; does the firewall allow Cloudflare |
| 522 | No TCP connection within Cloudflare's time limit | Server load, firewall dropping packets, wrong DNS record |
| 524 | A connection, but no HTTP response within 100 seconds | Slow requests: long queries, reports, exports, uploads |
The usual causes
- The application crashed or was killed while handling the request, so the connection closed with no response. PHP-FPM, Node.js or a container restarting under memory pressure are typical.
- The response headers are too large. Very large cookies, long redirect chains in headers or debug headers can exceed Cloudflare's header size limit.
- A firewall or security module reset the connection, for example a rule that treats Cloudflare's addresses as suspicious, or an intrusion prevention system on the origin host.
- Keep-alive mismatch. Cloudflare reuses connections to your origin. If the origin closes idle connections sooner than Cloudflare expects, a request can be sent on a connection that is already closing and come back empty.
- An invalid HTTP response, such as a backend that writes raw output before its headers, or a proxy in front of the app that returns an empty body on error.
Confirm it
Request the origin directly, bypassing Cloudflare, with the same host name. If the direct request also fails or hangs, the problem is on the server.
# replace 203.0.113.10 with your origin's IP address
curl -sv --resolve example.com:443:203.0.113.10 https://example.com/ -o /dev/null
# check the size of the response headers
curl -s -D - -o /dev/null https://example.com/ | wc -c# find the failing request in the web server and app logs around the error time
sudo tail -n 200 /var/log/nginx/error.log
sudo journalctl -u your-app --since "10 minutes ago"
# containers: was it restarted or OOM-killed?
docker ps -a --format '{{.Names}} {{.Status}}'Fix it
- Fix the crash you find in the log: a fatal error, an out-of-memory kill, a worker timeout. See 503 Service Unavailable for overloaded application servers and 500 Internal Server Error for application errors.
- Shrink the headers. Remove unneeded cookies, keep
Set-Cookievalues small, drop debug headers in production. - Allow Cloudflare's IP ranges in your firewall and security modules, so its connections are never reset.
- Raise the origin's keep-alive timeout (for example nginx
keepalive_timeout, Node.jsserver.keepAliveTimeout) so idle connections stay open at least as long as the proxy in front of them expects. - Retest directly and through Cloudflare with the same request.
Catch it before your visitors do
Cloudflare's error pages hide the cause, so measure both sides:
- Check the public URL through Cloudflare with an uptime monitor from several regions. That is what visitors get, 52x errors included.
- Check the origin directly with a second monitor on the origin's address or a health endpoint that bypasses Cloudflare. If only the first one fails, the problem is between Cloudflare and your server; if both fail, it is the server.
- Alert on the status code, not only on "down". A rule for any 52x response on the public check tells you which of the four errors it is before anyone opens a log.
- Keep the CF-Ray ID. It is in the error page and in the cf-ray response header; Cloudflare support and your own logs can be matched with it.
With APM on the origin you can also see the request that took 100 seconds behind a 524, instead of guessing.
Is error 520 Cloudflare's fault?
Rarely. Cloudflare returns 520 when your origin's response was empty, invalid or reset. Cloudflare's own outages usually show other errors and appear on its public status page.
Why does 520 only happen sometimes?
Intermittent 520s usually point to crashes under load, a worker pool that runs out, or keep-alive connections closed by the origin. Compare the error times with deploys, traffic peaks and restarts.
Can I just pause Cloudflare to fix it?
Pausing Cloudflare can help you test whether the origin answers directly, but the fix still has to happen on the origin, and pausing exposes the origin's address.
Check it now, free
- Is Cloudflare down? Live status: checked every few minutes, with outage history.
- Website down checker: Is it down for everyone or just me? Check any site now.
Related reading
- Cloudflare error 1016 "Origin DNS error": how to fix it: Fix Cloudflare error 1016 Origin DNS error: CNAME records pointing to names that do not resolve, deleted origins and load balancer pools, with checks.
- Cloudflare error 530: how to fix it: Fix Cloudflare error 530, usually shown with error 1033 (Argo Tunnel error) or 1016: stopped cloudflared tunnels, deleted tunnels and origin DNS problems.
- Cloudflare error 1015 "You are being rate limited": how to fix it: Fix Cloudflare error 1015 "You are being rate limited": what triggers rate limiting rules, how long blocks last, and how site owners tune them.
- Kubernetes HPA not scaling: how to fix it: Fix a Kubernetes HorizontalPodAutoscaler that will not scale: unknown metrics, missing CPU requests, metrics-server issues, tolerance and stabilization windows.
- Cloudflare error 523: origin is unreachable: Fix Cloudflare error 523 Origin is Unreachable: wrong DNS IPs, routing problems at the host and firewalls, with tests that confirm where traffic stops.
- React performance monitoring: Monitor React apps in production: Core Web Vitals from real users, slow renders and INP, bundle size, errors with source maps.
Watch your own site and services with VitalRix
Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.