VPS Tutorials
Cloudflare 524 on a VPS: Origin Timing, Nginx and Async Jobs (2026)
Trace the real timeout, compare origin paths, add Nginx timing logs and design durable asynchronous work with safe retries and authorized results.

A website opens normally, but a report export, image batch or AI request eventually returns Cloudflare Error 524: a timeout occurred. This usually concerns a connection already established while the origin does not complete the exchange in time; the error alone does not establish that the VPS lost networking.
Save the time, URL, method and Ray ID, then correlate origin logs. Identify the deadline before optimizing queries, repairing capacity, changing a justified timeout or moving the work to a queue. A 524 does not prove the background operation stopped. Do not repeatedly submit requests that write data.
This guide covers Cloudflare-proxied Linux VPS sites with Nginx and application services. The original documentation review was 15 October 2026; the official general limits referenced below still list the values shown. Tunnel, Workers, custom proxies and account-specific settings require their own checks.
| Symptom | Investigate | Next step |
|---|---|---|
| Cloudflare explicitly returns 524 | Established origin connection; response-read or request-write timeout | Origin processing, uploads and application resources |
| Cloudflare 522 | Establishment/acknowledgment of origin connection | Reachability, firewall and connection capacity |
| Nginx upstream timed out with 504 | Nginx's upstream deadline | Application/database and matching location |
| One export/generation route fails | Long work, queries, queues or external API | Time each stage; optimize or make asynchronous |
| Many routes slow together | Saturated workers/pools, CPU, I/O or memory | Limit expensive work and restore capacity |
Read error pages, status and logs together. With several proxies, the outer response may differ from the application's original status. See Cloudflare Error 524.
Cloudflare's general connection table lists:
- Proxy Read Timeout: 125 seconds, associated with 524; adjustable for Enterprise zones.
- Proxy Write Timeout: 30 seconds, also potentially producing 524; not adjustable.
The write limit concerns Cloudflare sending request data to the origin, not a universal 30-second total upload allowance. Special products differ: the 524 documentation lists 6.5 seconds for Cloudflare Images writes. Consult connection limits and the relevant product.
Changing proxy_read_timeout on the VPS to 600s does not change Cloudflare. Application workers, database drivers, external SDKs, browsers and gateways may expire sooner. Measure duration and compare actual product/account settings instead of concluding from “about two minutes.”
From browser Network tools, save:
- URL, method and status.
- Time/timezone, total duration and time to first byte.
cf-rayplus application request/job IDs.- Whether the request submitted an import, order, export or generation task.
Cloudflare forwards Ray IDs to the origin, where you can log them. They are not guaranteed unique; correlate time, path and application ID too. See Ray IDs.
For side effects, check existing task/business records before replaying. Use a safe repeatable read-only route for curl, not a loop of captured POSTs. Replace the domain and /status:
umask 077
curl --silent --show-error \
--connect-timeout 10 --max-time 160 \
--dump-header /tmp/cf524-edge-headers.txt \
--output /dev/null \
--write-out 'status=%{http_code} remote=%{remote_ip} dns=%{time_namelookup} connect=%{time_connect} tls=%{time_appconnect} first_byte=%{time_starttransfer} total=%{time_total}\n' \
'https://example.com/status'
A healthy check route does not establish the slow route recovered. --max-time 160 is this client's total deadline, not a server setting. curl can return exit 0 after HTTP 524: inspect status. A curl-side timeout is also different from receiving 524.
Timings are generally cumulative from request start, not independent stage durations; first-byte time includes earlier connection stages. See curl options. Restrict captured headers and remove cookies/tokens before sharing.
On an authorized machine able to reach the origin, --resolve retains hostname, Host and TLS SNI while selecting the origin IP. Replace documentation address 203.0.113.10; compare the same safe method, path and request conditions:
curl --silent --show-error \
--connect-timeout 10 --max-time 160 \
--noproxy 'example.com' \
--resolve 'example.com:443:203.0.113.10' \
--output /dev/null \
--write-out 'status=%{http_code} remote=%{remote_ip} first_byte=%{time_starttransfer} total=%{time_total}\n' \
'https://example.com/status'
An IP URL with a manual Host header does not replace hostname-aware HTTPS testing: SNI selects the certificate too. --noproxy avoids a local proxy altering the direct path; replace the domain throughout. See curl --resolve for --resolve.
A restricted Cloudflare-only, mutual-TLS or nonpublic origin may correctly reject direct tests. Use the origin itself or existing management network without permanently relaxing its firewall. Origin CA may require verified trust such as --cacert; keep TLS validation enabled. See Origin CA trust.
- Both paths slow: investigate the origin/shared dependencies.
- Only proxy fails, direct eventually finishes: an edge deadline may be involved; the long task still needs attention.
- Proxy cached, direct uncached: conditions differ and cannot identify the cause.
- Health check works, business route fails: keep tracing the original route.
Back up the actual configuration and retain existing logging. log_format belongs in http context, including a file genuinely included there, not server/location:
log_format cf524_timing escape=json
'{"time":"$time_iso8601","request_id":"$request_id",'
'"ray":"$http_cf_ray","method":"$request_method",'
'"uri":"$uri","status":"$status",'
'"request_time":"$request_time",'
'"upstream_connect_time":"$upstream_connect_time",'
'"upstream_header_time":"$upstream_header_time",'
'"upstream_response_time":"$upstream_response_time",'
'"upstream_status":"$upstream_status"}';
In the existing server being diagnosed, add:
access_log /var/log/nginx/cf524-timing.log cf524_timing;
Ensure the directory exists and follows service permissions/rotation. A server-level access_log affects inheritance; preserve required original destinations. The example excludes query strings, bodies and authentication headers, but sensitive path identifiers still require redaction/access controls. See Nginx logging and escaping.
For systemd-managed Nginx, validate before reloading:
sudo nginx -t && sudo systemctl reload nginx
sudo tail -n 50 /var/log/nginx/cf524-timing.log
sudo tail -n 100 /var/log/nginx/error.log
Containers/panels need their established validation/reload process and actual paths. Inspect:
request_time: total Nginx request handling, potentially including upload, upstream waiting and downstream transfer.upstream_connect_time: upstream connection time.upstream_header_time: wait for upstream headers.upstream_response_time: upstream response timing.
See upstream variables. Empty/- values may mean no upstream was used. Retries/multiple upstreams can produce multiple values, not a single number. After the edge times out, the origin may keep processing and log later or report 499 after downstream closure. Trace the timeline rather than requiring origin logs to contain 524.
Capture Linux host metrics near the incident:
date -u
uptime
free -h
df -h
df -i
vmstat 1 5
sudo journalctl -k --since '30 minutes ago' --no-pager |
grep -Ei 'out of memory|oom|killed process'
Missing matching logs do not disprove resource pressure.
| Evidence | Investigate | Possible response |
|---|---|---|
| Application starts work late | Occupied workers or pool waits | Bound concurrency and queue expensive work |
| Most time in the database | Plans, locks and result size | Indexes, smaller batches, pagination |
| External API stalls | SDK deadlines, provider and retries | Bounded deadlines; avoid nested retry multiplication |
| Sustained CPU/I/O saturation | Exports, compression, backups and other jobs | Scheduling, rate limits or appropriate capacity |
| OOM/restarts | Host/container allowance and concurrent memory | Resource/peak-load budgeting |
Idle-looking CPU can mean lock, pool or network waiting. One top screenshot is insufficient. A coding agent should correlate proxy entry, application start, connection checkout, dependency calls and response completion for one request ID before proposing changes.
Identify the real location and upstream protocol. proxy_pass applies to HTTP proxying; FastCGI/PHP-FPM uses its own directives. proxy_read_timeout defaults to 60 seconds between successive reads, not a total response duration. See Nginx semantics.
For a legitimate 70-second operation demonstrably cut off by Nginx at 60 seconds with 504, adequate capacity may justify a bounded 90-second value in that location. This does not repair multi-minute synchronous exports or extend Cloudflare. If normally short requests now approach two minutes, repair queueing/execution first: longer deadlines retain scarce resources longer.
For reports, batch generation, transcoding and lengthy AI work:
- Submit: authorize/validate, persist the task and reliably enqueue it; promptly return its ID.
- Execute: separate workers record queued/running/success/failure states.
- Track: clients poll with backoff and limits.
- Retrieve: provide authorized downloads/results after completion.
Submission may return HTTP 202 Accepted, meaning accepted rather than completed, with status information; see RFC 9110: 202. For example:
{
"job_id": "report-job-123",
"status": "queued",
"status_url": "/api/jobs/report-job-123"
}
This is an interface sketch, not a deployable queue. Implement durable jobs, submission idempotency, user isolation, timeout/failure states, cleanup and cancellation rules. An unpersisted web-process thread is insufficient. If submission itself times out, reconcile by idempotency key/task records before creating another. Status/download routes must verify ownership; knowing a job ID does not grant access.
Cloudflare suggests an unproxied dedicated subdomain for long requests, but this changes access paths, origin exposure, certificates, authentication and firewall/proxy protections. Assess those first; prefer controlled diagnosis or an existing management network. Origin CA may not be browser-trusted. Switching the entire production site mid-incident is not a verified application repair.
No. Official guidance allows Enterprise read limits up to 6000 seconds. Cache-rule methods also require genuinely cacheable content; use supported zone/rule capabilities. See Cloudflare-side remedies. Personal data, private results and user-specific endpoints must not be made public-cacheable to avoid timeouts.
Check protocol support, actual application flushes and proxy buffering. Arbitrary characters can corrupt JSON/files/API responses. Design supported progress streaming separately and verify the whole path; polling is often easier to test.
Yes. Edge waiting and business outcome differ. Check jobs/orders/data before retrying, with idempotency and reconciliation for writes.
- Original operation: same method, authorization and data scale succeeds.
- Edge path: final verification uses the real Cloudflare proxy.
- Capacity: inspect peak/tail latency, workers, pools and queues.
- Correct results: complete exports, no duplicate writes, explicit task states.
- Async lifecycle: quick submission, traceable jobs, terminal failure/cancellation and authorized results.
- Rollback: retain files/values; restore the intended configuration, run
nginx -t, then reload normally. - Diagnostics: retain/remove temporary logging deliberately, protect sensitive data and keep rotation working.
Observe the former data scale and normal peaks. Fewer 524s alone do not establish correct task completion.