Cloudflare Error 520 occurs when the origin server returns an empty, malformed or unexpected HTTP response that Cloudflare can not process. The server may still be running but a crashing application, invalid response headers or an incorrectly configured HTTP/2 connection can prevent Cloudflare from delivering the requested page.

To fix Error 520, identify the failing request and compare its response through Cloudflare with a direct request to the origin server. Then examine the relevant server logs, HTTP headers and connection settings to determine why the origin is not returning a valid response.

Why Cloudflare Returns Error 520

Cloudflare expects the origin server to return a properly formatted HTTP response when it forwards a request. Error 520 appears when that exchange produces an unexpected result, such as a connection closing before valid response headers arrive.

The problem does not necessarily affect an entire website. A homepage might load normally while a login request, form submission or particular application endpoint repeatedly returns Error 520.

Cloudflare identifies several possible causes:

  • An application or web server crashes before returning a valid response.

  • The origin sends malformed or incomplete HTTP headers.

  • Response headers exceed Cloudflare's 128 KB limit.

  • The origin advertises HTTP/2 support but handles the connection incorrectly.

  • Security software interrupts requests arriving through Cloudflare.

  • Authenticated Origin Pulls are enabled but incorrectly configured at the origin.

Each cause requires a different correction. The troubleshooting sequence below begins with the failing request and progressively narrows the investigation to the component responsible.

Step 1 — Identify the Failing Request

Start by determining whether Error 520 affects the entire website or only certain requests. This distinction helps identify whether the problem involves the general origin response or a particular application function.

Open the affected page and collect the following information:

  1. Copy the complete URL displaying Error 520.

  2. Record the failure time and timezone.

  3. Copy the Cloudflare Ray ID displayed on the error page.

  4. Test the homepage and another page on the same hostname.

  5. Repeat the failing request to determine whether the error occurs consistently.

Compare the results before making configuration changes.

Error patternFirst area to investigate
Every page returns Error 520Origin response and web server configuration
Only one URL failsApplication errors or page-specific responses
Error appears after loginSession processing and response cookies
Error occurs intermittentlyProcess crashes or unstable origin connections
Error started after an updateRecent application or server changes

For example, if Error 520 appears only after someone signs in, the authentication application's response and session handling deserve attention before unrelated server settings. If every URL fails, checking the origin's general response and error logs is a more useful starting point.

If the error disappears during testing, preserve the original Ray ID and timestamp. An intermittent failure may still be identifiable through logs recorded when the request failed.

Step 2 — Test the Origin Response

The next step is to establish whether the origin can return a valid HTTP response without Cloudflare's proxy handling the request. Comparing the proxied and direct-origin results can reveal whether the failure occurs inside the application or depends on the connection through Cloudflare.

Compare Both Connections

First, request the affected URL normally using curl:

curl -sv https://example.com/problem-page -o /dev/null

Replace the example URL with the actual failing address. Confirm whether Cloudflare returns Error 520 for the request.

Next, obtain the correct origin IP address from your hosting provider or server configuration. If the server supports direct HTTPS requests, run:

curl -sv --resolve example.com:443:203.0.113.10 \
https://example.com/problem-page -o /dev/null

Replace example.com with your hostname and 203.0.113.10 with the actual origin IP address. The example IP is reserved for documentation and is not a real hosting destination.

The --resolve option directs the request to the specified origin while preserving the hostname needed for HTTPS and virtual-host routing.

Reproduce the Original Request

The commands above perform GET requests, so they are appropriate when the failing page is accessed using GET. They do not automatically reproduce a login submission, an authenticated API request or another operation that uses POST or a different HTTP method.

For those failures, open the browser's Developer Tools, inspect the failed request under the Network tab and identify its method, request body, cookies and relevant headers. Where appropriate, use the browser's Copy as cURL feature to reproduce the request under controlled conditions.

Copied requests may contain session cookies or authorization tokens. Keep those details private, and do not publish the commands or share them without removing sensitive information.

A successful GET request does not establish that a failing POST request works correctly. The comparison must reproduce the original operation closely enough to investigate the same failure.

Interpret the Results

Direct-origin resultWhat to do next
Expected HTTP responseExamine differences between direct and proxied requests
HTTP 500 or application errorContinue to Step 3
Connection closes unexpectedlyInspect application and server logs
Malformed response headersContinue to Step 4
Connection refused or timed outCheck whether direct access is intentionally restricted

A direct request may fail because the origin deliberately accepts connections only from Cloudflare IP addresses. Similarly, an origin using a Cloudflare Origin CA certificate may fail ordinary client certificate verification even when its connection through Cloudflare is correctly configured.

Do not interpret either condition as proof that the origin is malfunctioning. If direct testing is restricted, ask your hosting provider to reproduce the request from an authorized environment.

Step 3 — Check Server Error Logs

If the direct-origin request fails or the connection closes unexpectedly, inspect the server logs from the time the error occurred. An application crash, terminated worker or unexpected upstream failure may prevent the origin from sending a complete response.

Find the Relevant Error

On a server using Nginx, check the error log:

sudo tail -n 100 /var/log/nginx/error.log

For Apache on Ubuntu or Debian, the command is commonly:

sudo tail -n 100 /var/log/apache2/error.log

These are common locations rather than universal paths. Managed hosting providers may expose the same information through their control panels, while PHP applications may maintain separate application or PHP-FPM logs.

Match the entries with the timestamp recorded in Step 1. Look for PHP fatal errors, application crashes, terminated processes or upstream connections that close unexpectedly.

Apply the Relevant Correction

Log evidenceCorrective action
PHP fatal errorIdentify and correct the failing code or plugin
PHP-FPM worker terminatedInvestigate memory usage and process failures
Upstream closed the connectionExamine the upstream application's logs
Web server process crashedInvestigate the crash and server configuration
Failure began after deploymentReview the changes and revert the responsible update if confirmed

If the logs identify a plugin that started failing after an update, temporarily reverting that specific update may help confirm the cause. Avoid disabling unrelated plugins or changing multiple settings simultaneously because doing so makes it harder to identify the actual correction.

After fixing the reported error, repeat the original request through Cloudflare. If the application logs no longer show failures but Error 520 continues, investigate the response headers.

Step 4 — Inspect HTTP Headers

The origin may be running normally while returning HTTP headers that Cloudflare cannot process. Cloudflare documents malformed responses and headers exceeding 128 KB as possible causes of Error 520.

Large or repeatedly generated cookies can contribute to this problem, particularly on websites with authentication and session-related functionality. The important check is whether the failing response contains invalid or unusually large headers.

Examine the Response

Use curl to inspect the headers returned directly by the origin:

curl -sS -D - -o /dev/null \
--resolve example.com:443:203.0.113.10 \
https://example.com/problem-page

Replace the example hostname and IP address with your actual configuration. This command performs a GET request and displays the response headers while discarding the response body.

Look for the following problems:

  • Unusually large or duplicated Set-Cookie headers.

  • Malformed HTTP header names or values.

  • Missing or incomplete response headers.

  • A connection that closes before a valid response arrives.

For an authenticated or POST-related failure, inspect the headers produced by that actual request rather than assuming the GET response will be identical.

Correct the Header Failure

If the response contains excessive cookies, identify the application component generating them. Reduce unnecessary cookie data, correct duplicated headers or repair session handling that repeatedly appends information.

If the response is malformed, inspect the application or web server responsible for generating those headers. Correct the formatting problem and repeat the same request to confirm that the origin now returns a valid response.

If the headers appear valid, continue to the HTTP/2 check. An origin can respond correctly through one protocol while failing when Cloudflare uses another.

Step 5 — Test HTTP/2 to Origin

Cloudflare Error 520 can occur when an origin server advertises HTTP/2 support but does not handle the connection correctly. The server might return valid HTTP/1.1 responses while failing to process HTTP/2 requests from Cloudflare.

Cloudflare provides a setting that allows administrators to test this possibility without disabling the entire proxy. The change affects communication between Cloudflare and the origin rather than the visitor's browser connection.

Temporarily Disable HTTP/2

Follow this sequence:

  1. Sign in to the Cloudflare dashboard.

  2. Select the affected domain.

  3. Open Speed → Settings → Protocol Optimization.

  4. Locate HTTP/2 to Origin.

  5. Record its current state and temporarily disable it.

  6. Repeat the request that previously produced Error 520.

If the error disappears, investigate the origin's HTTP/2 implementation and web server configuration. Check the relevant error logs for protocol failures, unexpected connection closures or incompatibilities introduced by recent updates.

Correct the confirmed origin problem before deciding whether HTTP/2 to Origin can be re-enabled.

If Error 520 continues, restore the original setting and move to the next diagnostic check. An unchanged result does not justify leaving HTTP/2 disabled permanently.

Step 6 — Compare Cloudflare and Origin Results

If the direct-origin request works but Cloudflare continues returning Error 520, examine the response information Cloudflare records for the same request. This can help determine whether the origin returned an HTTP status that Cloudflare could not deliver or whether the connection failed before a response was received.

Check Response Statuses

If Cloudflare Origin Analytics is available for your account, compare these values for the affected endpoint:

  • originResponseStatus — the HTTP status returned by the origin.

  • edgeResponseStatus — the HTTP status Cloudflare delivered to the visitor.

Cloudflare Logs may also provide corresponding OriginResponseStatus, EdgeResponseStatus, and CacheStatus fields.

The differences can narrow the investigation.

Origin statusEdge statusWhat it suggests
200520Origin responded but Cloudflare could not process the response correctly
0520No origin HTTP response was recorded; investigate the connection and response headers
503520Origin reported a server error; investigate the associated application or server failure
200200The request completed successfully

An origin status of 200 with an edge status of 520 can indicate malformed headers or another response-processing problem. Compare the affected request with the header checks in Step 4 and the corresponding origin logs.

An OriginResponseStatus of 0 requires more care because it does not always indicate an origin failure. Cloudflare can also record 0 when it serves a cached response without contacting the origin.

Check CacheStatus in the same log record. A cache hit or revalidated response may explain the absence of origin contact, while a cache miss or expired response combined with Error 520 points toward a failed origin exchange.

Check Origin Security

If the evidence suggests that Cloudflare's connection is being interrupted, inspect the origin's security logs for the same timestamp. Look for a firewall, security plugin or Authenticated Origin Pull configuration terminating or rejecting the connection.

Correct only the rule or configuration shown to be responsible. Avoid disabling the entire firewall or removing origin authentication without confirming that either is causing the failure.

A connection explicitly refused by the origin is a different troubleshooting problem, covered in BusinessTally's Cloudflare Error 521 guide. Connection timeouts are addressed separately in its Cloudflare Error 522 guide.

The investigation here should remain focused on why Cloudflare receives an unexpected or unusable origin response.

Step 7 — Verify the Correction

After correcting the suspected cause, test the same request that originally failed. Loading the homepage successfully does not establish that a login request or page-specific Error 520 has been resolved.

Use the original URL, request method and relevant authentication conditions wherever possible. Then confirm that the correction remains effective during repeated requests.

Verify these results:

  1. The affected request returns its expected response through Cloudflare.

  2. The origin returns valid HTTP responses where direct testing is permitted.

  3. The previously identified server or application error no longer appears in logs.

  4. The failure does not recur during repeated tests.

  5. Related application functions continue operating correctly.

If the original failure was intermittent, monitor the affected endpoint under similar conditions. A single successful request may not reveal a process crash or connection problem that occurs only during particular operations.

Where Cloudflare response analytics are available, confirm that the affected endpoint no longer produces unexplained 520 edge responses. If Error 520 reappears, compare its new timestamp and Ray ID with the original evidence before making another change.

If Error 520 Still Appears

If the error continues after the origin response, server logs, HTTP headers, HTTP/2 configuration and relevant connection restrictions have been investigated, collect the evidence needed for further diagnosis. The objective is to identify the failing exchange rather than repeatedly modify unrelated Cloudflare settings.

Ask the Hosting Provider to Investigate

Prepare the following information:

  • The complete URL returning Error 520.

  • The failure time and timezone.

  • The Cloudflare Ray ID.

  • The results of proxied and direct-origin tests.

  • Relevant application, web server and security logs.

  • Recent changes to the application or origin configuration.

Ask the hosting provider to inspect the failing request and determine whether the origin closed the connection, produced an invalid response or encountered a server-side failure.

If ordinary application logs show nothing unusual, the provider may need to inspect a reverse proxy, load balancer or other intermediary between Cloudflare and the application. These components can interrupt a response without generating an obvious application-level error.

Escalate to Cloudflare Support

If the hosting provider confirms that the origin is responding correctly but Error 520 remains, contact Cloudflare Support through your available support channel.

Cloudflare recommends providing the affected URLs, Ray IDs, diagnostic trace output and HAR files captured with Cloudflare enabled and temporarily bypassed.

The diagnostic trace can be accessed at:

https://example.com/cdn-cgi/trace

Replace the example hostname with your website's domain. Review any collected HAR files before sharing them because they may contain session cookies, authorization headers or other sensitive information.

A temporary proxy bypass should only be attempted after confirming that the origin can safely accept direct traffic. BusinessTally's guide to disabling Cloudflare without website downtime explains the necessary certificate, firewall and origin-access checks.

If the website works when Cloudflare is bypassed, that result helps isolate the failure to the proxied connection path. It does not establish that the underlying origin-response problem has been corrected, so preserve the comparison evidence and continue investigating the failed request.