VPS Tutorials
How to Fix Cloudflare Error 520 on a VPS
Compare the same request at Cloudflare and your VPS origin, then check Nginx logs, headers, cookies, and HTTP/2 to find the cause of a 520.

Your VPS still serves the homepage, but opening the account page brings up Cloudflare Error 520. Save the failing URL and the Ray ID. Then request that same page through Cloudflare and from your origin to see where their responses diverge.
A 520 means Cloudflare received an empty, unexpected, or unusable response from the origin. A crashed application, a closed connection, oversized headers, and a broken origin HTTP/2 setup can all produce the same error. The response that comes back from the origin is the starting point. Cloudflare’s Error 520 documentation
| What you see | Where to look |
|---|---|
| The origin also returns an empty reply, resets the connection, or sends a 5xx | Match the request to your web server, application, and kernel logs |
| Only signed-in sessions or one route fail | Compare cookies and headers for that request |
| HTTP/1.1 works at the origin and HTTP/2 fails | Check negotiation and HTTP/2 at the TLS endpoint |
| The origin works and Cloudflare still returns 520 | Check which origin and protocol Cloudflare uses, plus the firewall and client-certificate configuration |
Capture the URL, method, timestamp with time zone, and Ray ID. You can get the Ray ID from the error page or the cf-ray response header in your browser’s Network panel. Keep any query parameters that affect the result, and redact credentials and tokens before sending the URL or logs to anyone.
If the browser fails during sign-in, save the failing request before trying an anonymous GET. A working GET only proves that particular request can get through. Use a test account and a staging environment to check an action such as submitting a form or paying. You can use the Ray ID when logs record it, and narrow the search with the host, path, and time. Cloudflare Ray ID reference
Use your VPS or Cloudflare origin configuration to find the origin IP. Replace the example host, address, and path below. The example assumes HTTPS on port 443 with the public hostname configured on the origin. If an Origin Rule overrides the port, HTTP Host, or TLS SNI, account for those settings when you compare.
SITE='www.example.com'
ORIGIN='203.0.113.10'
URL="https://$SITE/account"
curl --noproxy '*' -sS --max-time 20 -D - -o /dev/null "$URL" \
| grep -Ei '^(HTTP/|cf-ray:|cf-cache-status:)'
curl --noproxy '*' -sS --max-time 20 \
--resolve "$SITE:443:$ORIGIN" -o /dev/null \
-w 'origin: status=%{http_code} http=%{http_version}\n' "$URL"
The --resolve option changes the address for this one curl invocation. The URL still supplies the HTTP Host and TLS SNI. The edge response includes cf-cache-status when Cloudflare provides it. A cache hit can come back without contacting the VPS, so test the failing dynamic route. If curl prints status 000, read its error output to see where it stopped before getting an HTTP status. Cloudflare’s curl troubleshooting guide · curl’s --resolve reference
If your firewall only allows Cloudflare, perform the application check from an authorized internal network or the VPS itself, using an address the intended virtual host listens on. A listener that enforces Authenticated Origin Pulls (AOP) can reject ordinary curl requests by design. An origin using a Cloudflare Origin CA server certificate also requires a suitable trust chain in curl. Keep both the firewall and certificate checks in place. Authenticated Origin Pulls documentation
Look at the proxy, application, and kernel logs in the same window. These examples assume systemd, Nginx, and PHP 8.3. Replace the unit names, log path, and time window with yours. If the app runs in a container, pull its logs for the same period.
sudo journalctl -u nginx -u php8.3-fpm --since '15 minutes ago' --no-pager
sudo journalctl -k --since '15 minutes ago' --no-pager \
| grep -Ei 'out of memory|oom|killed process'
sudo tail -n 100 /var/log/nginx/error.log
A killed PHP worker and a matching kernel out-of-memory (OOM) event point you toward memory usage and the workload that triggered it. If you just see the connection close, compare the logs of every proxy or load balancer in front of the app. Nginx’s return 444 closes the connection before sending response headers. If the request landed in the default virtual host, check the actual Host value against the intended server_name. If a security rule matched the wrong request, adjust its scope. Validate any Nginx change with sudo nginx -t before reloading the service. Nginx return directive
Cloudflare lists a 128 KB total limit for request headers and a separate 128 KB limit for response headers. A browser sends Cookie on the request. Your app sends Set-Cookie on the response. Try the same flow with a clean browser session. If it works with fresh cookies, look for cookies written by multiple apps on the same domain, overly broad scopes, or a session cookie that grows with use. Cloudflare request and response limits
With the same variables, estimate the HTTP/1.1 response header size and count the Set-Cookie fields without printing their contents. For an authenticated route, the anonymous result may differ. Use a local test session when checking sign-in. This count includes the status line and separators and serves as a clue. Your proxy or app can have its own lower limit.
if HEADERS=$(mktemp); then
if curl --noproxy '*' -sS --max-time 20 --http1.1 \
--resolve "$SITE:443:$ORIGIN" -D "$HEADERS" -o /dev/null "$URL"; then
wc -c < "$HEADERS"
awk 'tolower($0) ~ /^set-cookie:/ {n++} END {print "Set-Cookie fields:", n+0}' "$HEADERS"
fi
rm -f "$HEADERS"
fi
If the origin already returns a 502 and its Nginx log says upstream sent too big header, the failing hop is between Nginx and the app behind it. Check whether the app can send smaller headers before changing Nginx’s upstream buffers. Diagnose oversized upstream headers in Nginx
If you have a load balancer or separate IPv4 and IPv6 origins, check every active destination. Look for dropped Cloudflare traffic in your cloud security group and host firewall, then check that the proxy and origin agree on AOP. A successful request against one address covers only that address. Cloudflare’s guidance on allowing its IP ranges
If the errors started after an HTTP/2 or TLS proxy change, compare those requests with the same domain and URL. Use curl -V to check that your build lists HTTP2.
for version in --http1.1 --http2; do
curl --noproxy '*' -sS --max-time 20 "$version" \
--resolve "$SITE:443:$ORIGIN" -o /dev/null \
-w 'status=%{http_code} http=%{http_version}\n' "$URL"
done
Look for http=2 in the second result to verify that HTTP/2 was actually negotiated. A pair of successful requests can miss intermittent resets or errors under multiplexing. If the evidence points to the origin protocol, record the current setting and use a maintenance window to test with HTTP/2 to Origin off under Speed → Settings → Protocol Optimization. Once the origin or intermediate proxy is fixed, retest with your intended settings. Cloudflare HTTP/2 to Origin documentation
Repeat the operation that failed, with the right route and login state. Verify that the request reaches the origin and that the app responds as expected. For intermittent failures, recheck during the same traffic window and compare the edge result with origin logs. If the error persists, send the URL, timestamp and time zone, Ray ID, relevant logs, and any requested redacted HAR through a private support channel. Cloudflare’s troubleshooting evidence checklist
Next step: compare the actual plans
Filter the listed plans by budget, specifications and region, or start with a buying guide.