FULL AI ANALYSIS

NGINX reverse proxy returns 413 for Transfer-Encoding: chunked uploads to Next.js API while direct Node accepts them

Generated Oct 24, 2026, 9:21:01 AM

Analysis summary

NGINX may buffer request bodies by default; for chunked Transfer-Encoding it needs to accumulate the body to measure size unless proxy_request_buffering is disabled. If buffering is enabled and NGINX determines the body exceeds client_max_body_size (or buffer settings disallow chunked streaming), it returns 413. Disabling request buffering streams chunks straight to the upstream (Next.js), enabling uploads without size checks by NGINX. Proper config is to set proxy_request_buffering off in the upload endpoint location or use client_body_in_file_only to stream to disk, then proxy_pass.

Possible causes

NGINX request buffering/size-check behavior with chunked Transfer-Encoding causes size check to fail and trigger 413

95%

client_max_body_size not applied to the specific location block due to include/overrides or vhost mismatch

40%

Upstream returning 413 but being masked as NGINX error (less likely given upstream logs)

20%

Suggested fixes

1

Diagnostic step 1

Immediate test: in your upload location add proxy_request_buffering off; reload nginx and retry chunked upload. Verify success.

2

Diagnostic step 2

If you need buffering for other endpoints, scope proxy_request_buffering off to only the upload route (location /api/upload { proxy_request_buffering off; proxy_pass http://upstream; }).

3

Diagnostic step 3

Alternative: enable client_body_in_file_only on and let NGINX stream to disk: client_body_in_file_only on; client_body_temp_path /var/tmp/nginx-client-body; then proxy_pass.

4

Diagnostic step 4

Ensure client_max_body_size is set in the correct server/location block and reload nginx after changes. Monitor NGINX error.log for 'client intended to send too large body' entries for regressions.

5

Diagnostic step 5

Test with curl using Transfer-Encoding: chunked to confirm behavior: curl -H 'Transfer-Encoding: chunked' --data-binary @largefile http://your-nginx/upload