How to Fix “Web Server is Returning an Unknown Error (Error Code 520)”

Illustration of Error Code 520 Web Server is Returning an Unknown Error

Quick Answer

The “Web server is returning an unknown error (Error Code 520)” is a Cloudflare-specific response indicating that your origin server returned an empty, unknown, or unexpected response to Cloudflare. To fix it immediately: Check your origin server’s error logs, ensure your web server hasn’t crashed, disable overly restrictive firewall rules that might be blocking Cloudflare’s IP addresses, and verify that your HTTP response headers are not exceeding the 8KB limit.

Understanding the 520 Error: The Cloudflare Handshake

When you use a reverse proxy or Content Delivery Network (CDN) like Cloudflare, your website sits behind a protective shield. When a visitor types in your URL, their browser connects to Cloudflare, and Cloudflare acts as the middleman, pulling the data from your actual hosting provider (the “origin server”).

Error Code 520 acts as a “catch-all” error. It means Cloudflare reached out to your origin server, but the server responded in a way that violated standard HTTP protocols. Because Cloudflare doesn’t know how to interpret the broken response, it throws the 520 error to the end user.

Primary Causes Behind Error Code 520

  • Connection Resets: The origin server abruptly drops the TCP connection after the initial handshake.
  • Header Size Limits: Your server is generating HTTP headers that exceed Cloudflare’s strict 8KB (8,192 bytes) size limit. This frequently happens with bloated cookies.
  • Empty Responses: The origin server returns an empty string instead of a valid HTTP status code (like 200 OK or 404 Not Found).
  • IP Blocking: Your host’s security firewall or ModSecurity rules are mistakenly blacklisting Cloudflare’s connecting IP addresses.

Is TorBox Down? Check Server Status, Outages & Quick Fixes

Diagnostic Matrix: Fixing the 520 Error

Use this diagnostic table to isolate your specific backend issue and apply the correct server-side fix:

Origin Server Symptom Underlying Cause Required Action
PHP fatal errors in Apache/Nginx logs A broken plugin/script is crashing the response. Disable recent plugins and check error_log for the exact broken script.
Connections blocked at firewall level Host is rate-limiting Cloudflare IPs. Whitelist all official Cloudflare IPv4/IPv6 ranges in your server firewall.
520 error only on POST requests (logins/carts) HTTP Headers exceed 8KB size limit. Clear browser cookies, reduce cookie generation in your web application.

TL;DR: The 520 Error Checklist

  • It is a Host Issue: Cloudflare is working perfectly; your actual origin server is the one returning a bad response.
  • Check Firewalls: Ensure your hosting provider has whitelisted all Cloudflare IP addresses.
  • Review Logs: Check your Apache/Nginx error logs for PHP crashes or database timeouts happening at the exact time of the error.
  • Pause Cloudflare: Temporarily pause Cloudflare in your dashboard to see if your site loads directly from the server. If it throws a 500 Internal Server Error, you have found the root cause.
  • Header Size: Ensure you aren’t storing too much data in cookies, which causes headers to exceed 8KB.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply