Guides
8 min readUpdatedError 520: web server returned an unknown error (causes and fixes)
Quick answer
Error 520 is a Cloudflare status meaning the origin server answered the edge with something it could not use: an empty reply, a reset connection, a response that is not valid HTTP, or response headers over the 128 KB limit. Visitors can only wait and reload. Site owners request the origin directly with curl --resolve and match the result to a cause, such as a crashed web server, a catch-all rule that returns nothing, or oversized cookies.
01What does error code 520 mean?
Cloudflare's documentation defines 520 as the error it returns when "the origin server returns an empty, unknown, or unexpected response". The edge connected to the origin and sent the request, then got back something it could not turn into a response for the visitor.
520 is not a standard HTTP status: the IANA registry lists 512 to 599 as unassigned. The closest standard code is 502 Bad Gateway, which RFC 9110 defines as an invalid response from an inbound server, and other proxies report the same situation as a 502.
Visitors can only wait a minute and reload. For site owners a 520 is an origin diagnosis: a direct request and the origin's error log show what went wrong.
02Error 520 vs 521, 522, 524 and the rest of the 52x family
The 52x codes are close relatives; what separates them is how far the edge got. The full list, with the 1xxx codes, is in the Cloudflare error codes guide.
| Code | How far the edge got | Typical cause | Closest standard code |
|---|---|---|---|
| 520 | Connected and sent the request; the answer was empty, reset or malformed | Crashed web server, catch-all rule returning nothing, headers over 128 KB | 502 |
| 521 | Connection refused | Web server stopped, or a firewall rejecting the edge | 502 |
| 522 | No SYN-ACK within 19 seconds, or no acknowledgement within 90 | Firewall silently dropping the edge, overloaded host | 504 |
| 523 | No route to the origin address | Wrong A or AAAA record, routing fault | 502 |
| 524 | Connected, but no response within 125 seconds | Slow application or database query | 504 |
| 525 | TLS handshake failed | No certificate, no SNI support, cipher mismatch | 502 |
| 526 | Certificate failed validation in Full (strict) mode | Expired, self-signed or wrong-name certificate | 502 |
| 527 | Railgun listener error; Railgun support ended on 31 January 2024 | No longer documented | None |
| 530 | Origin name could not be resolved; the body carries a 1xxx code | Origin DNS or tunnel errors such as 1016 or 1033 | 502 |
03Step 1: request the origin directly
Send the origin the same request the edge sends. curl's --resolve option maps the hostname to the origin's address for one command, so the Host header and TLS server name stay correct and the origin picks the same virtual host and certificate.
Use the exact failing URL, not just the home page, because 520s are often path-specific: one PHP page that crashes the server, or one response that sets far too many cookies. Run the test from a machine the origin firewall allows. If the origin accepts only the proxy's published ranges, as it should once you hide the origin IP, run it on the origin itself.
curl -sS -o /dev/null -w 'status=%{http_code} header_bytes=%{size_header}\n' \
--resolve www.example.com:443:203.0.113.10 https://www.example.com/failing/path
echo "curl exit code: $?"
# the handshake, the negotiated protocol (ALPN) and every response header
curl -sv -o /dev/null --resolve www.example.com:443:203.0.113.10 https://www.example.com/failing/path
# the same request forced to HTTP/1.1, to compare with HTTP/2
curl -sS -o /dev/null --http1.1 -w 'status=%{http_code}\n' \
--resolve www.example.com:443:203.0.113.10 https://www.example.com/failing/path04Step 2: match the curl result to a cause
In every row the edge generates the error page, but the fault sits in the origin or just in front of it.
| curl shows | What the origin did | Likely cause | Fix |
|---|---|---|---|
| curl: (52) Empty reply from server | Took the request and closed the connection without a byte | A web server worker crashed, or a catch-all rule such as nginx's return 444 matched the hostname | Read the error log for crashes; give the hostname its own server block |
| curl: (56) Recv failure: Connection reset by peer | Reset the connection | A host firewall, IPS or security module killing connections from the proxy's addresses, or a crash | Allow the provider's ranges; read the security tool's own log |
| curl: (1) Received HTTP/0.9 when not allowed | Sent bytes that are not an HTTP response | A non-HTTP service on the port, or an application printing output before its headers | Point the origin record at the right port and service |
| Status 200 but header_bytes above 131072 | Sent valid headers too big for the edge | Too many or too large Set-Cookie headers, leftover debug headers | Cut headers below 128 KB, as in the calculation below |
| HTTP/1.1 works, HTTP/2 fails | Advertised HTTP/2 through ALPN, then broke it | Incomplete HTTP/2 support in the origin or a module in front of it | Fix the origin's HTTP/2, or turn off HTTP/2 to the origin at the provider |
| Everything works directly | Fails only for requests from the edge | Firewall or rate limit on the proxy's addresses, authenticated origin pulls misconfigured, idle connection closures | Compare origin logs at the Ray ID's time |
05What the origin logs show during a 520
A 520 caused by a crash often leaves no line in the access log, because the worker died before it could write one. A request in flight when its worker is killed can leave only an error-log alert like the one below, while the client sees an empty reply. Search the error log at the same second instead.
On Apache httpd, the matching event is a notice numbered AH00052 that a child process exited on a signal. With mod_php, a PHP crash takes the Apache child down with it, which fits Cloudflare's note that 520s are prevalent with certain PHP applications that crash the web server. With PHP-FPM behind nginx, a crashed PHP worker becomes a 502 from nginx instead, so visitors see a 502.
# nginx error.log: a worker crashed mid-request (signal 11 is a segmentation fault)
[alert] 190431#190431: worker process 190432 exited on signal 11
# nginx access.log: the catch-all server closed the connection, status 444, 0 bytes
127.0.0.1 - - [24/Oct/2026:12:34:30 +0000] "GET / HTTP/1.1" 444 0 "-" "curl/7.88.1"
# Apache error_log: the same event (pid illustrative)
AH00052: child pid 4711 exit signal Segmentation fault (11)
# was the web server killed for memory in the last hour?
journalctl -k --since '-1 hour' | grep -i 'out of memory'06Are the response headers too large? A worked calculation
Cloudflare's limits page sets a total of 128 KB for response headers (131,072 bytes, reading KB as 1,024 bytes), and its 520 page names oversized headers, often from excessive cookies, as a cause. RFC 6265 asks browsers to support cookies of at least 4,096 bytes each, so an application that keeps state in cookies can approach that size per cookie. The browser then sends those cookies back with every request, where the same bloat can cause Request Header Or Cookie Too Large.
The arithmetic is short. One Set-Cookie line with a three-character name and a 4,000-byte value is 4,018 bytes: 12 for "Set-Cookie: ", 4 for the name and the equals sign, 4,000 for the value and 2 for the line end. 32 such cookies take 128,576 bytes and still fit under 131,072, while 33 take 132,594 and do not, before any other header is counted.
Fix it at the source: keep session state on the server behind one small session cookie, scope cookies to the paths that need them, and drop debug headers in production. Where nginx proxies to the application, a header block this large normally fails earlier with "upstream sent too big header", a 502 covered in the 502 guide.
curl -s -o /dev/null -w '%{size_header}\n' --resolve www.example.com:443:203.0.113.10 https://www.example.com/
# how many cookies a single response sets
curl -s -D - -o /dev/null --resolve www.example.com:443:203.0.113.10 https://www.example.com/ | grep -ci '^set-cookie:'07Why do 520 errors come and go?
Intermittent 520s usually have a timing cause rather than a broken page.
- Idle connections. The edge reuses connections to the origin; Cloudflare lists a 900-second proxy idle timeout and a 30-second TCP keep-alive interval, both with 520 as the status at the limit, and advises keeping HTTP keep-alive enabled on the origin because it helps avoid connection resets.
- Restarts. Recycled workers, a service restart or a deploy that replaces the process can drop the requests in flight.
- Memory pressure. The kernel's out-of-memory killer ends a large process, often the web or application server, together with every connection it held.
- One bad path. A single endpoint that crashes or sets huge cookies produces 520s only for visitors who reach it, which looks random until you group the errors by URL.
- Floods. An HTTP flood that exhausts memory or workers turns into crashes and resets, and then into 520s for everyone.
log_format edge '$remote_addr [$time_iso8601] "$request" $status $body_bytes_sent '
'rt=$request_time ray=$http_cf_ray';
access_log /var/log/nginx/access.log edge;
# resulting line (example Ray ID)
127.0.0.1 [2026-10-24T12:38:36+00:00] "GET / HTTP/1.1" 200 3 rt=0.000 ray=8f1c2a3b4d5e6f70-AMS08What a reverse proxy or WAF can and cannot do about 520s
A proxy changes how you hear about a failure; it does not stop the origin failing.
- It can tell you which side failed, through the code and the Ray ID, which a bare connection error in a browser never does.
- It can keep floods and abusive bots away from the origin, removing a common reason web servers run out of memory or workers and crash.
- A WAF can block the specific requests that trigger a known crash until the code is fixed, a technique called virtual patching.
- It can serve cached copies of pages during an origin failure, but only where the provider and your cache rules allow stale content.
- It cannot repair a crashing worker, a broken HTTP/2 implementation or oversized cookies; those are origin fixes.
- Switching the proxy off is a diagnostic only. If the error disappears, the cause is in the edge-to-origin path, but the origin address is now public, so switch it back on.
Questions
Frequently asked questions
- 01Is error 520 my fault as a visitor?
- No. A 520 means the website's own server sent the provider's edge an empty, broken or unexpected answer, so nothing in your browser caused it. Wait a minute and reload once, because many 520s come from a brief crash or restart. If it persists, tell the website the time, the page address and the Ray ID.
- 02Is a 520 error a Cloudflare outage?
- Rarely. A 520 reports a problem between the edge and one website's origin server, so it normally affects that site alone while others on the same network work. A provider incident shows up as errors on many unrelated sites at the same moment and on the provider's public status page. If only one site fails, its origin is the place to look.
- 03Why do I get a 520 only on some pages?
- Because the cause is often tied to one URL. A single page may run code that crashes the web server, or set so many cookies that its headers pass the 128 KB limit, while other pages are fine. Group the 520s by URL, then request the worst one directly from the origin with curl.
- 04How do I find the request behind a 520 in my logs?
- Take the time and Ray ID from the error page, convert the time from UTC, and search the origin's error log at that second, since a crashed worker often leaves no access-log line. Logging the cf-ray request header makes later searches much faster, because each line then carries the Ray ID the visitor saw; match the time as well, since Ray IDs are not guaranteed to be unique.
- 05Will pausing Cloudflare fix a 520?
- It removes the edge from the path, which is a useful test: if the origin works directly, the problem lies in how it treats requests from the edge, such as a firewall rule or an HTTP/2 issue. It fixes nothing and exposes the origin's address to attackers, so turn the proxy back on after the test.
Sources
Sources and verification
The configuration and commands on this page are examples, not a tested recipe. Adapt them to your system and check them before use (nginx -t for nginx).
- 01Error 520 · Cloudflare docs
- 02Connection limits (header limits, idle and keep-alive timeouts) · Cloudflare docs
- 03Cloudflare 5xx errors · Cloudflare docs
- 04Error 502 bad gateway or error 504 gateway timeout · Cloudflare docs
- 05Cloudflare is deprecating Railgun · Cloudflare blog
- 06Troubleshooting Cloudflare 5XX errors, including 527 Railgun Listener to origin error (archived 5 January 2022) · Internet Archive
- 07Hypertext Transfer Protocol (HTTP) Status Code Registry · IANA
- 08RFC 9110, HTTP Semantics, section 15.6.3: 502 Bad Gateway · RFC Editor
- 09RFC 6265, HTTP State Management Mechanism, section 6.1: limits · RFC Editor
- 10Module ngx_http_rewrite_module: return and code 444 · nginx.org
- 11curl man page: --resolve, write-out variables and exit codes · curl
- 12Apache httpd source, server/mpm_unix.c (AH00052) · Apache Software Foundation
Last updated