By Greg Nowak. Last updated 2026-11-26.
When a 502 comes and goes, pick one failed request before raising a timeout or restarting NGINX. In a stack with Cloudflare in front of NGINX and an application behind it, follow that request from the client response to the proxy log and then to the application. You’re looking for who sent the 502 and how far the request got.
Save the timestamp with its time zone, the hostname, HTTP method, path, and any request ID the client received. Pull a successful request from the same route and time window. That gives you something to compare while the route is still serving traffic.
Did Cloudflare generate the 502?
Cloudflare can send its own 502 or pass along a 5xx from the origin. If it’s safe to repeat the request, send Accept: application/problem+json. In Cloudflare’s default structured response, cloudflare_error: true tells you Cloudflare generated the error. Keep the Ray ID and timestamp, and use the detail field, when present, to decide what to check first on the path to the origin. Custom Errors can change what comes back, so an HTML response leaves the question open. Cloudflare error responses
Look for that request in NGINX using an ID both systems recorded. If you only have the hostname, method, path, and time window, treat the match as tentative when several entries fit. If nothing turns up, confirm you’re looking at the intended origin and the right access log. Check whether buffering could delay the entry or conditional logging could skip it. NGINX logs the request under the location where processing ends, which can change after an internal redirect. NGINX HTTP log module
Read the NGINX attempts in order
$status is the response code NGINX sent. Read it alongside $upstream_addr and $upstream_status to see which backend it selected and what status it recorded for that attempt. If NGINX couldn’t select a server, $upstream_addr contains the group name and $upstream_status records 502. Start there by checking which servers in that group were eligible to handle the request. NGINX HTTP log module · NGINX upstream module
Commas separate attempts within a group. A colon separator marks a change of upstream group after an internal redirect. Match each address to the status and timings in the same position. $upstream_connect_time covers connection setup, including the TLS handshake for HTTPS backends. $upstream_header_time measures how long it took to receive the response headers, and $upstream_response_time measures the time spent receiving the upstream response. Look at the successful sample too. A retry can give the client a successful response while the log still shows that an earlier backend attempt failed. NGINX upstream module
Check what the application saw
Once you have a backend address, look for the same request in that service’s logs. An arrival entry confirms the request made it to the service. If that’s the last entry, use the matching NGINX error and any application spans to see what happened after it arrived. If the application logged a completed error response, send the service owner that record along with the matching proxy attempt and its timing.
On instrumented HTTP paths that use W3C Trace Context, OpenTelemetry carries the context in traceparent. The trace ID ties work across services together, and the span ID identifies the operation within the trace. With log correlation configured, those IDs let you jump from a log entry to its span. Use the successful request to check that the ID you plan to search for makes it through the proxy and into the application log. OpenTelemetry context propagation
| What you found | Who starts | First check |
|---|---|---|
| Cloudflare generated the 502 and classified it as an origin error | CDN and origin operator | Use the Ray ID, timestamp, and error detail to investigate the path from Cloudflare to the origin. |
NGINX logged a group name in $upstream_addr and 502 in $upstream_status |
NGINX operator | Check which backends in the group were eligible to serve the route at the time. |
| NGINX logged a backend address and a connection setup error | NGINX and backend platform operators | Match the error and timing to the attempt. Check connectivity to that backend and the TLS handshake if configured. |
| The matching application log shows a completed error response | Application owner | Open the application span and inspect any downstream calls it records. |
When the November NGINX fix matters
NGINX mainline 1.31.10, released on 23 November 2026, fixed an issue that could drive up CPU use when NGINX connected to backends over TLS. If the affected route uses HTTPS upstreams, check the deployed build and compare NGINX CPU and upstream connection timings during the failure window. If the pattern fits, factor the fix into the upgrade decision and compare the same signals after rollout. NGINX mainline changelog
Set up the next on-call engineer
Set the NGINX access log format to capture the hostname, route, timestamp, correlation ID, final status, and total request time. Include the upstream addresses, statuses, and timings in attempt order, and keep that order through the log pipeline. If the pipeline only saves the last upstream status, a successful retry can hide the earlier failure from a search. NGINX HTTP log module · NGINX upstream module
Alert on the 502 rate clients see for each route and show the request count alongside it so whoever gets paged can judge the scale. Give them a view of upstream attempts to see whether failures cluster in one backend pool or route. Put the first log query in the runbook, along with the ID to carry between systems and the evidence each owner needs to take over. Greg can help piece together the Cloudflare, NGINX, and application records, then use what turns up to build the alerts and write the runbook with your team.
Related on GrN.dk
- Apache 2.4.68: What to Check Before You Call It Patched
- AI Content and Google: Fix the Process Before You Publish More
- AI Workflow Retries: Stop One Request Becoming Two Jobs
Need help with this kind of work?
Talk to Greg about tracing intermittent 502s and giving your on-call team route-level alerts and a runbook. Get in touch with Greg.