Skip to content

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.

ErrorWhat Cloudflare sawWhere to look first
520A connection, then an empty, invalid or reset responseOrigin application and web server error logs
521The origin actively refused the TCP connectionIs the web server running; does the firewall allow Cloudflare
522No TCP connection within Cloudflare's time limitServer load, firewall dropping packets, wrong DNS record
524A connection, but no HTTP response within 100 secondsSlow 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.

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

  1. 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.
  2. Shrink the headers. Remove unneeded cookies, keep Set-Cookie values small, drop debug headers in production.
  3. Allow Cloudflare's IP ranges in your firewall and security modules, so its connections are never reset.
  4. Raise the origin's keep-alive timeout (for example nginx keepalive_timeout, Node.js server.keepAliveTimeout) so idle connections stay open at least as long as the proxy in front of them expects.
  5. 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:

  1. Check the public URL through Cloudflare with an uptime monitor from several regions. That is what visitors get, 52x errors included.
  2. 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.
  3. 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.
  4. 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.

Frequently asked questions

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

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.