Cloudflare error 520 means the origin web server returned an empty, unknown, or unexpected response to Cloudflare. Cloudflare connected to the origin, but what came back was not a normal HTTP response. Visitors cannot fix it. Site owners start with the origin error logs, because a crashed app process is the most common cause.
Cloudflare's own documentation puts the fix on the origin side. Its owner steps are to set the DNS record to DNS only or pause Cloudflare as a workaround, ask the host to review origin error logs for crashes, and check HTTP/2 to origin. The rest of this guide shows how to find which of those applies.
Quick fix for site owners:
- Check the origin error logs at the time of the 520. Look for crashes, especially PHP or app worker crashes.
- Check the response header size. Cloudflare returns 520 when headers exceed 128 KB, which large cookies often cause.
- If you enabled HTTP/2 to origin, check the origin's HTTP/2 setup or turn that setting off.
- Confirm that no firewall or security plugin blocks or rate limits Cloudflare IP addresses.
- As a short-term workaround, set the DNS record to DNS only or pause Cloudflare while you debug.
Visitors: refresh once and wait a few minutes. If the error stays, tell the site owner the URL, the time, and the Ray ID at the bottom of the error page.
What causes Cloudflare error 520
Cloudflare's documentation lists these causes:
- The origin server crashed or is misconfigured. Cloudflare notes this is common with some PHP applications.
- A firewall or security plugin on the origin blocks Cloudflare IP addresses.
- Response headers are larger than 128 KB, often because of too many or too large cookies.
- The origin sent an empty response with no HTTP status code or body.
- The response is missing headers or is not a valid HTTP error response.
- HTTP/2 is configured incorrectly at the origin.
- Authenticated Origin Pulls is on, but the origin is not set up for it.
Those causes are the ones Cloudflare lists as of its documentation update on June 16, 2026. Hosting guides add two more that fit the same pattern: an origin under heavy load that drops connections, and short idle timeouts that close a connection Cloudflare tries to reuse. Neither is in Cloudflare's list, so confirm them in your own logs before you change timeouts.
520 often appears after a deploy. A new plugin, middleware, or auth flow can add cookies or break responses on some routes only. It can also come and go if one server in a load-balanced pool is broken.
| Cause | How to confirm | Fix |
|---|---|---|
| App or PHP worker crash | Log entries at the 520 timestamp, such as segfaults, out-of-memory kills, or restarts | Fix the crash, restart the worker, add memory or limits |
| Oversized response headers | Header size near 128 KB in the curl test below | Trim cookies and custom headers |
| Firewall blocks Cloudflare | Requests from Cloudflare never appear in access logs | Allow Cloudflare IP ranges in every layer |
| HTTP/2 to origin misconfigured | 520 stops after you turn off HTTP/2 to origin | Fix the origin's HTTP/2 setup or leave it off |
| Authenticated Origin Pulls mismatch | 520 started after you turned the setting on | Install the Cloudflare client certificate on the origin |
Header limits changed in October 2025
Many guides still quote 16 KB per header or 32 KB total. Cloudflare raised the limit on October 16, 2025. Its changelog says Cloudflare now supports up to 128 KB for both request and response headers, and expects fewer 520 errors from oversized response headers as a result. If a guide tells you to cut headers under 16 KB, it predates that change. Keep cookies small anyway. A header-size 520 now means the response is four times larger than the old 32 KB cap.
Error 520 vs. 521 and 522
These three errors are easy to confuse. The difference is where the connection fails.
| Error | What happened | First check |
|---|---|---|
| 520 | Cloudflare connected, but the response was empty, invalid, or reset | Origin logs, crashes, header size |
| 521 | The origin refused the connection | Web server running, port open, Cloudflare IPs allowed |
| 522 | The connection attempt timed out | Firewall drops, overload, network path |
| 525 | The TLS handshake with the origin failed | Origin certificate and SSL mode |
If the origin refuses the connection, read the 521 guide. If the connection never completes, read the 522 guide. If the TLS handshake fails, read the 525 guide. If Cloudflare connects but gets a strange response, stay with 520. If the hostname is served by a Cloudflare Worker and the page says "Worker threw exception", read the error 1101 guide instead.
How to debug error 520 on your origin
Start with the exact failing request. Record the URL, the time, and the Ray ID. Check Cloudflare's status page first. If nothing is reported, the cause is almost certainly your origin or a layer in front of it.
1. Test the origin without Cloudflare. Send the request straight to the origin IP but keep the real hostname. Replace example.com and 203.0.113.10 with your values:
curl -sv -o /dev/null --resolve example.com:443:203.0.113.10 https://example.com/failing-path
Read the output:
curl: (52) Empty reply from servermeans the origin closed the connection without a response. That is a typical 520 cause.Connection reset by peermeans a process or device reset the connection. Check the app server, reverse proxy, and any security tool.- A normal status line and headers means the origin works for this request. Compare with what Cloudflare gets, for example by IP or by HTTP version.
2. Measure the response header size. This prints the size of the headers in bytes:
curl -s -D - -o /dev/null --resolve example.com:443:203.0.113.10 https://example.com/failing-path | wc -c
If the result is near 128 KB (131072 bytes), reduce cookies or remove large custom headers. Test as a logged-in user too, because auth cookies often add the most size.
3. Check the logs at the same time. Search the web server, reverse proxy, and app logs for the timestamp. Look for segfaults, out-of-memory kills, worker restarts, and upstream "prematurely closed" messages. On nginx the line reads upstream prematurely closed connection while reading response header from upstream, and it means the app process behind nginx died or closed the socket before it sent headers.
sudo tail -n 200 /var/log/nginx/error.log | grep -i "prematurely closed"
sudo dmesg -T | grep -i "out of memory"
If there is no log entry at all for the failing request, something in front of the web server rejected it, such as a firewall, a load balancer, or a DDoS filter at the host.
4. Check HTTP/2 to origin. If you turned on HTTP/2 to origin in Cloudflare, confirm the origin supports it correctly. Cloudflare's docs suggest disabling it under Speed > Settings > Protocol Optimization to test.
5. Check Cloudflare access to the origin. Confirm that firewalls, fail2ban, and security plugins do not block or rate limit Cloudflare IP ranges. If you use Authenticated Origin Pulls, confirm the origin has the correct client certificate setup.
6. Compare upstream servers. If the error is intermittent, test each server in the pool directly. One server with an old build or broken config is enough to cause random 520s.
WordPress and PHP sites
Most 520 reports on small sites come from PHP. Work through these in order and test the failing URL after each one.
- Restart PHP-FPM, for example
sudo systemctl restart php8.3-fpmwith your PHP version in the unit name. - Check the PHP error log for fatal errors and memory limit messages.
- Rename
.htaccesstemporarily on Apache. A bad rewrite or header rule can produce a malformed response. WordPress regenerates it from Settings > Permalinks. - Deactivate plugins one at a time, starting with security, caching, and anything that sets cookies.
- Clear the site and object cache, then retest.
If the site works with Cloudflare paused and fails with it on, go back to the firewall and header checks. Those are the two causes that only show up behind the proxy.
What to send Cloudflare support
If the origin looks healthy and 520 continues, Cloudflare support asks for:
- The full URL that failed
- The Ray ID
- The output of
https://example.com/cdn-cgi/tracefor your domain - Two HAR files of the failing request, one with Cloudflare on and one with Cloudflare off
You can open the HAR files in our HAR analyzer to compare the two captures before you send them.
How to fix error 520 as a visitor
The problem is between Cloudflare and the website's server, so you have little control.
- Refresh once.
- Wait a few minutes and try again.
- Check whether other pages on the site load.
- Send the URL, time, and Ray ID to the site owner.
Clearing cookies for that one site can help if the site stored very large cookies in your browser. It does not fix a crashed origin.
Can proxies fix error 520?
Usually not. Error 520 is not a block on your IP or a rate limit. It is an origin server failure. A new IP sends the same request to the same broken origin.
There is one exception. Some origins run security tools that reset connections from traffic they flag, and Cloudflare reports that as a 520. If the same URL loads in a normal browser on another network but returns 520 from your client or IP, treat it as a soft block. Compare the failing request with a real browser capture in the HAR analyzer, and check your headers against our web scraping headers guide. If every client and IP gets 520, the origin is broken and no proxy will help.
520 during retail drops and ticket on-sales
Origins often buckle at the start of a drop or an on-sale, and the first symptom is a burst of 520s and other 5xx errors. Hammering retries makes it worse and can turn an overload into an actual rate limit. Back off per IP, keep checkout sessions on their stable IPs, and resume when a plain page load works again. If you also see 429s, that is the rate limit case, which needs a different fix.
If you scrape or monitor a site and see 520, log the URL and time, and count 520s apart from access blocks so they do not hide real blocks.
How to prevent error 520
- Alert on app crashes, worker restarts, and 5xx spikes.
- Keep cookies and custom headers small, and set a size budget.
- Use health checks that load real routes, not only open ports.
- Keep all servers in a pool on the same build and config.
- Test deploys through Cloudflare, not only against the origin.
- Keep Cloudflare IP ranges allowed in every firewall layer.
FAQ
What does Cloudflare error 520 mean?
It means the origin web server returned an empty, unknown, or unexpected response to Cloudflare.
What does "the origin web server returned an invalid or incomplete response to Cloudflare" mean?
It is the plain description of error 520. Cloudflare reached the origin, but the origin crashed, reset the connection, sent no status line, or sent headers that Cloudflare could not accept.
Is error 520 caused by Cloudflare?
Usually not. The cause is almost always the origin application, web server, reverse proxy, firewall, or response format.
Can large cookies cause error 520?
Yes. Cloudflare returns 520 when response headers exceed 128 KB, a limit it raised from 32 KB total on October 16, 2025. Many large cookies are a common way to reach that limit.
How long does Cloudflare error 520 last?
It lasts until the origin returns a valid response again. A crashed worker that restarts clears in seconds. A bad deploy, an oversized cookie, or a firewall rule stays broken until someone fixes it.
How do I fix error 520 on WordPress?
Restart PHP-FPM, read the PHP error log, rename .htaccess, and deactivate plugins one at a time. If the site works with Cloudflare paused, check that the host firewall allows Cloudflare IP ranges.
Is error 520 the same as error 522?
No. Error 522 means Cloudflare could not finish the connection to the origin in time. Error 520 means Cloudflare connected but got an invalid response.
Final thoughts
Error 520 is an origin problem that Cloudflare only reports. Read the origin logs at the failing timestamp first, then measure header size, then check that Cloudflare IPs are allowed through every firewall. Pause Cloudflare to confirm the proxy path is involved, but do not leave it paused. If you automate against a site, count 520s separately from blocks and back off when they spike.
Technical references: Cloudflare error 520 documentation and the Cloudflare header limit changelog.