Question

How to fix Cloudflare 524 timeout occurred

524 means Cloudflare connected to origin but the response took too long.

What to do first

  1. Find slow URLs with timing checks.
  2. Inspect DB and upstream dependencies for bottlenecks.
  3. Move long jobs to async processing.

If you are not sure whether your failure is timeout or malformed response, check Cloudflare 520 vs 524 quick split.

First-response command block

# Compare latency: proxied path vs direct origin
time curl -s -o /dev/null -w '%{http_code}\n' https://yourdomain.com/your-heavy-endpoint
time curl -s -o /dev/null -w '%{http_code}\n' --resolve yourdomain.com:443:ORIGIN_IP https://yourdomain.com/your-heavy-endpoint

# Host pressure check
top -bn1 | head -n 20
vmstat 1 5
iostat -xz 1 3

# Service and app logs
sudo journalctl -u caddy --since '30 minutes ago' --no-pager | tail -n 120
sudo journalctl -u nginx --since '30 minutes ago' --no-pager | tail -n 120

How to read the result

Low-risk fix order

  1. Reduce endpoint work inside request cycle (query optimization, pagination, cache).
  2. Move long tasks to queue/background workers.
  3. Add cache headers for repeat-read pages where safe.
  4. Re-test for 30-60 minutes on the same endpoint before wider changes.

Recovery signal

A stable recovery pattern is: target endpoint returns mostly 200/301/304, and 524 stops repeating on your top public pages.

If the issue is connection refusal (not timeout), continue with Cloudflare 521 web server down.

Generate full 524 checklist