Web Development
VERIFIED FIXES

NGINX returns 413 for Transfer-Encoding: chunked uploads only when proxying to Node.js over HTTP/2 TLS offload

Environment

Environment

NGINX acting as TLS terminator and HTTP/2 front-end (Linux host). Backend is a Node.js Express app running on localhost:3000 over HTTP/1.1. Large client uploads sent with Transfer-Encoding: chunked; direct requests to Node (bypassing NGINX) succeed.

Symptoms

Symptoms

Clients uploading chunked POST bodies receive 413 Request Entity Too Large from NGINX. Error occurs only when TLS/HTTP2 is enabled on the front-end; disabling HTTP/2 or sending with Content-Length succeeds.

Observations

Observations

NGINX error.log shows 'client intended to send too large body' even though client_max_body_size increased to 100M. Access logs show no Content-Length header. Proxy config used proxy_http_version 2 by default; proxy_request_buffering was on. Proxying to HTTP/1.1 backend previously worked for non-chunked flows.

Already attempted

Already attempted

Increased client_max_body_size to 200M, added proxy_buffering off, restarted nginx, switched proxy_http_version to 1.1 (temporary) which allowed chunked uploads to succeed, tried setting chunked_transfer_encoding on but earlier config had no effect.

Question

Question

What's the minimal, safe NGINX configuration change to accept Transfer-Encoding: chunked uploads from HTTP/2 clients while continuing to proxy to an HTTP/1.1 Node backend? How to verify and rollback?

COMMUNITY RESPONSES

Verified community troubleshooting

1 reply
0
viggovpn Answer
user
Posted 4w ago • 0 confirmations

Make NGINX proxy the HTTP/2 client stream as HTTP/1.1 to the Node backend and disable request buffering for streaming uploads. In your location block add: proxy_http_version 1.1; chunked_transfer_encoding on; proxy_request_buffering off; ensure client_max_body_size is set in the same context. Test with curl --http2 --chunked-transfer and the same large file; you should see the upload reach Node without a 413. If anything breaks, revert the nginx config and reload; this change is reversible and safe to test in staging first.

Showing 1 of 1 community responses
AI DIAGNOSTICS

Incident analysis

Updated 4w ago• Trouble ID

Most likely causes

HTTP/2 frontend to HTTP/1.1 backend protocol mismatch with NGINX using HTTP/2 proxying features expecting Content-Length 90%
proxy_request_buffering enabled causing NGINX to reject large streaming uploads when Content-Length absent 70%
client_max_body_size interpreted before proxy translation in the HTTP/2 handler due to configuration location/context 40%

Summary

413 for chunked uploads in a setup where NGINX fronts with HTTP/2 and proxies to HTTP/1.1 usually stems from an HTTP/2-to-HTTP/1.1 translation issue: NGINX needs to buffer or convert chunked streams properly. If proxy_http_version is left at 2 or buffering is enabled, NGINX may expect Content-Length and reject chunked payloads. The successful test switching proxy_http_version to 1.1 indicates the problem is protocol mismatch and buffering. Settings that commonly fix this are proxy_http_version 1.1, chunked_transfer_encoding on (to allow sending chunked to backend), and proxy_request_buffering off for streaming uploads.

Suggested Fixes

Diagnostic step 1
In the relevant server/location block, set: proxy_http_version 1.1; chunked_transfer_encoding on; proxy_request_buffering off;
Diagnostic step 2
Ensure client_max_body_size is set in the same context that handles the request (server or location) and reload nginx (nginx -t && nginx -s reload).
Diagnostic step 3
Reproduce upload with curl using --http2 and --chunked-transfer to verify successful proxied streaming: curl --http2 -X POST -H 'Transfer-Encoding: chunked' --data-binary @largefile https://yourdomain/upload

Continue troubleshooting

Matched from the title, description and tags