Skip to main content
HTTP/5xx (Server Error)

520 Web Server Returned an Unknown Error

Cloudflare-specific: the origin server returned an empty, unknown, or unexpected response.

❓ Why does this happen?

Origin crashed, reset the connection, or sent headers exceeding Cloudflare's 32 KB limit.

✅ How to fix it

Check origin server error logs, disable firewall rules blocking Cloudflare IPs, and reduce response header size.

Return or handle 520 in your stack

// Note: 520 is normally generated by Cloudflare, not your app.
// Emitting it yourself is only useful for testing client error handling.
// app/api/resource/route.ts
export function GET() {
  return Response.json(
    { error: "Web Server Returned an Unknown Error", status: 520 },
    {
      status: 520
    }
  );
}

Live 520 mock endpoint

Point your app, tests, or retry logic at this free public URL to reproduce a real 520 response (CORS enabled, optional ?delay=ms up to 5000).

https://castov.com/api/mock/520

520 vs similar status codes

Frequently Asked Questions

What does HTTP Status 520 mean?
Cloudflare-specific: the origin server returned an empty, unknown, or unexpected response.
Why am I getting a 520 status code?
Origin crashed, reset the connection, or sent headers exceeding Cloudflare's 32 KB limit.
How do I fix a 520 Web Server Returned an Unknown Error error?
Check origin server error logs, disable firewall rules blocking Cloudflare IPs, and reduce response header size.
What is the difference between 520 Web Server Returned an Unknown Error and 502 Bad Gateway?
520 is Cloudflare's catch-all for an empty or unexpected origin response; 502 is the generic gateway error from other proxies.
How can I test how my app handles a 520 response?
Send a request to https://castov.com/api/mock/520 — it returns a real 520 Web Server Returned an Unknown Error response with CORS enabled. Add ?delay=2000 to simulate a slow server.

Other 5xx status codes

Browse the full HTTP status codes directory or troubleshoot terminal errors in the Error Fix Encyclopedia.