How to Fix Cloudflare Error 520: Web Server is Returning an Unknown Error

If your Cloudflare server receives a request it cannot interpret, it returns Error 520: Web Server Is Returning An Unknown Error.

Cloudflare Error 520 1

Need a fix now? Click here to go straight to the troubleshooting steps.

What is Cloudflare Error 520: Web Server is Returning An Unknown Error?

Cloudflare Error 520 is a server-side diagnostic message indicating that even though a request reached the origin web server, the server received an invalid HTTP response or didn’t know how to interpret the request at all and was unable to proceed.

A program using excessive resources may need to stop, or too many visitors may overload the server. These are the usual causes.

How To Fix Cloudflare Error 520: Web Server is Returning an Unknown Error

  1. Search Error Logs For Device Resets
  2. Restart PHP Applications On Your Origin Server
  3. Whitelist Your Cloudflare Origin Server IP Address
  4. Check Response Headers From Your Cloudflare Origin Web Server
  5. Lighten Your Cookie Load
  6. Correct Your Cloudflare Origin Server DNS Settings
  7. Examine Your Server Traffic
  8. Check For Non-HTTP Errors In Your Cloudflare Logs

1. Search Error Logs For Device Resets

Search Error Logs

Updating or resetting the origin server or network equipment after a successful TCP handshake leaves the connection’s headers outdated. The server then cannot handle further requests.

A page refresh typically clears error 520 quickly without further action.

If visitors repeatedly receive error status 520, one of your devices may be resetting unexpectedly.

Check your Cloudflare origin web server logs for error 520 occurrences and connection resets.

Compare the log entries with uptime records for your firewall and load balancer, as well as your origin server or other network hardware.

If unexpected resets are responsible, move the device’s update or reboot schedule to your routine maintenance window.

Restart the Cloudflare origin server on the new schedule to make existing sessions reconnect.

2. Restart PHP Applications On Your Origin Server

In the server error logs, check whether PHP applications are failing or consuming excessive resources.

PHP applications may provide critical site services at the application layer of the OSI model. If one crashes at this layer, users may receive error 520 despite having an active connection.

The 520 error should clear after you restart the affected application.

Always-online services are more likely to overload and crash. Schedule reboots during routine maintenance to prevent this.

To automate those reboots, create a cron job. This can prevent always-online services from overloading and causing error 520.

3. Whitelist Your Cloudflare Origin Server IP Address

Cloudflare’s security protocols require you to whitelist your origin web server IP addresses through the Cloudflare dashboard.

Whitelist Ip Addresses

An explicitly blocked IP address sometimes produces a more specific Cloudflare error code.

An unidentified connection that has not been whitelisted leaves the server unable to handle it, producing error 520.

Correct the A records to whitelist the relevant IP addresses.

Check that your CNAME records are correct and whitelist every CNAME associated with the web server in DNS settings. Otherwise, error 520 or a similar message may appear.

4. Check Response Headers From Your Cloudflare Origin Web Server

Error 520 commonly results from missing or empty response headers sent by your Cloudflare server.

Inspect origin response headers in the Cloudflare server’s HAR (HTTP Archive) files.

Follow this guide to locate and open your HAR files. They may contain sensitive data.

Several different problems can cause missing response headers.

Investigate with a debugger such as Wireshark or Fiddler. These tools can help trace requests and the data they contain.

A response from an outdated user agent, or web browser, may indicate an old version of Internet Explorer or Safari.

Check compatibility with common web browsers. You will sometimes still see connections from less common user agents.

5. Lighten Your Cookie Load

Use Fewer Cookies

A complex web service may depend on more cookies to handle its requests efficiently.

Cookies increase the size of the HTTP response header attached to a request. Cloudflare limits these headers to 8KB or less.

Beyond that header limit, the origin server cannot parse the complete connection request. It responds with a protocol-violation warning or an HTTP response that times out because of rate-limiting rules.

Review response headers in your server’s HAR files to check for excessive or oversized cookies.

The HTTP archive contains an example of your header output.

If headers are larger than the host’s 8KB HTTP header limit, work with your web developer to optimise the cookies.

6. Correct Your Cloudflare Origin Server DNS Settings

An empty server response contains none of the information or data the site is meant to send.

This often points to incorrect or outdated web server settings for your hosting provider.

The easiest way to check whether your DNS information is correct is to ask your host.

Corrected Cloudflare DNS settings may take up to 72 hours to propagate, depending on the host. An escalated support ticket can contribute to that wait.

The host may also need to flush its DNS cache, extending the wait further.

If DNS errors caused the missing or invalid HTTP response headers, warn your team and users of possible site outages lasting up to 3 days.

After changing DNS settings, clear your site cache, including the DNS cache and any WordPress plugin caches.

7. Examine Your Server Traffic

Check Your Traffic

Start by looking for unusual server traffic.

Filter requests on port 80 to restrict suspicious traffic and block spam connections. Overload from these connections can cause errors 520 or 503.

Block connections when many share the same IP address and ray ID within a short period.

Cloudflare proxy traffic must be whitelisted. Check error logs for blocked proxy IP connections that you intend to allow.

Even with valid headers, permitted traffic on port 80 can time out if the origin server responds too slowly. That timeout may be unrelated to server rate limits.

Unexpected timeouts can produce error 520. Inspect HAR records for requests carrying excessive or malformed data.

8. Check For Non-HTTP Errors In Your Cloudflare Logs

Error 520 covers situations where the server cannot recognise an incoming request.

Common HTTP problems have their own error codes. Error 520 often appears when a non-HTTP problem prevents a server connection or causes a gateway timeout.

Inspect system resources and network hardware for services that have stalled or crashed.

Search device error logs for “520” to find the Cloudflare response code.

If error 520 remains after checking devices and traffic, open tickets with Cloudflare and your hosting provider so they can investigate their systems.

If you’re looking for (free) tips to optimize your site speed with Cloudflare and rank higher on Google, you can follow me on Twitter 👉🏻 @bitofseo.

Please DM me if you have any questions about this Cloudflare article (or have some feedback to make it better 😄️).

About Jake Sacino

After working as an engineer and consultant for a bunch of big companies, Jake now works as a full-time SEO & software engineer.