NGINX returns 413 Request Entity Too Large for chunked uploads only when client uses Transfer-Encoding: chunked
Environment
Nginx 1.18 on Ubuntu 20.04 proxying to a Node.js 14 upload endpoint; client uploads use Transfer-Encoding: chunked (no Content-Length). client devices include mobile browsers and curl.
Symptoms
Large uploads (>5MB) occasionally receive 413 errors when sent with chunked encoding. Same clients succeed when sending with explicit Content-Length (standard multipart/form-data). NGINX error.log shows 'client intended to send too large body' only for chunked requests.
Observations
client_body_max_size in nginx.conf set to 8m. For chunked requests, NGINX first buffers body to client_body_temp_path; disk space is sufficient. Increasing client_body_buffer_size didn't help. Upstream logs show no request arriving for the failing chunked attempts. curl -T with --upload-file (sets Content-Length) succeeds consistently.
Already attempted
Increased client_body_max_size to 100m, cleared temp path, reloaded nginx — still saw 413 for some chunked uploads. Tried disabling buffering (proxy_request_buffering off) but failures persisted for certain clients.
Question
Why does NGINX reject chunked uploads with 413 even when client_body_max_size is larger than the upload, and how to accept chunked uploads reliably while maintaining buffering protections?
Verified community troubleshooting
NGINX treats chunked bodies differently and can hit buffering limits before Content-Length checks. First check client_body_temp_path permissions and inspect temp files for failing uploads. As a quick test, set proxy_request_buffering off on the upload location so the upstream gets the chunked stream directly; if uploads succeed, you know NGINX buffering is the issue. Then tune client_body_max_size and client_body_buffer_size or keep buffering off and harden upstream to handle backpressure. Verify by reproducing the chunked upload with curl and watching nginx logs; roll back buffering changes if upstream resource issues appear.
Incident analysis
Most likely causes
Summary
Suggested Fixes
Continue troubleshooting
Related troubles
Matched from the title, description and tags
- Web Development49% match
NGINX returns 413 for Transfer-Encoding: chunked uploads only when proxying to Node.js over HTTP/2 TLS offload
Solved1 answer - Web Development45% match
NGINX reverse proxy returns 413 for Transfer-Encoding: chunked uploads to Next.js API while direct Node accepts them
Open0 answers - Web Development45% match
Next.js serverless API returns 502 for large Transfer-Encoding: chunked uploads only when behind NGINX reverse proxy
Open0 answers - Web Development43% match
NGINX HTTP/2 proxy drops chunked Transfer-Encoding uploads to Next.js API routes — request body never reaches Node
Solved1 answer - Networking40% match
Chunked Transfer-Encoding uploads fail with 413 only through TLS-terminating NGINX proxy
Open0 answers