Web Development
VERIFIED FIXES

NGINX HTTP/2 proxy drops chunked Transfer-Encoding uploads to Next.js API routes — request body never reaches Node

theocode
4w ago
Environment

Environment

Ubuntu 20.04 server running NGINX 1.22 (compiled with http2), backend is Next.js API routes served by Node 18 behind a unix socket. Clients use modern browsers over HTTPS with HTTP/2 enabled. NGINX proxy_pass to http://unix:/var/run/next.sock:; body size limit default.

Symptoms

Symptoms

Large chunked POSTs to /api/upload are rejected by NGINX with 413 or behave as if empty body forwarded; Node logs show no body or early EOF. Direct requests to Next.js (bypassing NGINX) succeed. Small non-chunked POSTs work fine. Problem only occurs when client uses HTTP/2 to NGINX; HTTP/1.1 clients through same NGINX succeed.

Observations

Observations

NGINX error.log shows 'client intended to send too large body' intermittently and 'upstream sent no chunked data while requesting body'. client_max_body_size is at default 1m. fastcgi is not used. tcpdump shows the client sending DATA frames; NGINX sometimes responds with RST_STREAM for the stream. Upgrading NGINX to a build with http2 changes didn't help.

Already attempted

Already attempted

Increased client_max_body_size in site conf to 100m, restarted NGINX. Added proxy_request_buffering off; no change. Tested with curl using --http2 -v and saw early 413 when request exceeded ~1MB. Direct Node access tested OK. Tried proxying to backend over HTTP/1.1 (h2 disabled on listen) — then chunked uploads succeed.

Question

Question

What NGINX or HTTP/2 proxy settings are causing chunked Transfer-Encoding bodies to be dropped or rejected when using HTTP/2, and how to make NGINX reliably forward chunked uploads to the Next.js backend without disabling HTTP/2?

COMMUNITY RESPONSES

Verified community troubleshooting

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

Most often this is the proxy buffering/size path: add a larger client_max_body_size and disable buffering for the upload route. In your location block set client_max_body_size 200m; proxy_request_buffering off; proxy_http_version 1.1; proxy_set_header Connection "";. Restart nginx and retry with curl --http2 -v to confirm Node receives the POST body. If uploads still fail, enable nginx debug for http2/proxy to capture DATA frame handling, and consider testing with an upstream over HTTP/1.1 to isolate an http2-to-upstream translation bug. Roll back changes if other endpoints regress.

Showing 1 of 1 community responses
AI DIAGNOSTICS

Incident analysis

Updated 4w ago• Trouble ID

Most likely causes

NGINX client_max_body_size or proxy buffering limits trigger early 413 for HTTP/2 DATA frames before body forwarded. 85%
proxy_request_buffering behavior with HTTP/2 in current NGINX build has a bug/regression in how chunked frames are handled. 50%
Upstream unix-socket configuration or proxy_pass header translation mishandles Transfer-Encoding when HTTP/2 client requested it. 30%

Summary

Symptoms indicate NGINX is enforcing buffer/body sizing or mishandling HTTP/2 DATA frames when proxying to a backend over an http1-style upstream. HTTP/2 uses DATA frames that NGINX translates; default client_max_body_size and proxy buffer settings can trigger early 413 responses. proxy_request_buffering off usually helps for large streaming uploads, but combined with HTTP/2 there are known interactions where NGINX expects to buffer the full request. The fact HTTP/1.1 clients succeed suggests the HTTP/2 to upstream translation path and buffering limits are at fault.

Suggested Fixes

Diagnostic step 1
Set client_max_body_size to the expected max (e.g., 200m) in the server/location block and reload NGINX.
Diagnostic step 2
Disable request buffering for the proxied location: 'proxy_request_buffering off;' then reload NGINX.
Diagnostic step 3
Ensure proxy_http_version is 1.1 and that 'proxy_set_header Connection "";' is present so NGINX uses chunked transfer to upstream correctly.

Continue troubleshooting

Matched from the title, description and tags