FULL AI ANALYSIS

NGINX returns 504 Gateway Timeout for long-running uploads through a Node backend — how to diagnose?

Generated Nov 6, 2026, 9:29:48 AM

Analysis summary

504 indicates Nginx gave up waiting for upstream to respond. For uploads, Nginx may buffer request body to disk before forwarding, or timeouts may fire while waiting for slow client body arrival. Key checks: whether Nginx is buffering body (client_body_in_file_only), whether timeouts occur before Node finishes processing, and whether Nginx is attempting to read response headers while still receiving body. The different outcomes point to client slowness, proxy buffering, or upstream processing delays.

Possible causes

Nginx times out waiting for slow client body or upstream response (proxy_read_timeout/proxy_send_timeout too low).

7%

Nginx request-body buffering writes to temp disk and stalls due to slow disk or small client_body_buffer_size.

5%

Node blocks while processing multipart stream because of synchronous disk operations or memory pressure causing slow response.

5%

Intermediate network (clients on cellular) stalling uploads long enough to trigger Nginx timeouts while direct connection benefits from different TCP path/MTU.

3%

Suggested fixes

1

Diagnostic step 1

Reproduce with access logging at upstream and proxy levels: log request start/complete timestamps in Node and enable Nginx logs with $request_time and $upstream_response_time for the same request. Result meaning: If Nginx request_time >> Node processing time and Node shows incomplete body receipts, the timeout is due to slow client upload and Nginx reading body. If Nginx times out after Node completed processing, focus on Nginx→upstream response path or buffering.

2

Diagnostic step 2

Check whether Nginx buffers client body to disk by inspecting client_body_temp_path during reproductions (ls -l /var/lib/nginx/body) and set client_body_buffer_size larger for a short test. Result meaning: If temp files appear and grow during uploads and disk I/O spikes, buffering to disk is active and slow disk or small buffer sizes could be contributing. If no temp files appear, Nginx may be streaming directly to upstream.

3

Diagnostic step 3

Temporarily increase proxy_read_timeout and proxy_send_timeout for a test location and reproduce from a slow client; also test direct Node path concurrently. Result meaning: If increasing timeouts prevents 504s, the issue is timeouts against slow clients or long upstream processing; if 504s persist despite long timeouts, investigate network resets or upstream crashes.