Networking

Chunked Transfer-Encoding uploads fail with 413 only through TLS-terminating NGINX proxy

Environment

Environment

Ubuntu 22.04 host running NGINX 1.22 as TLS terminator with http2 enabled (ssl_server block), backend Node.js 18 app on 127.0.0.1:3000 (HTTP/1.1). Clients upload multipart/form-data via curl and browser POSTs using Transfer-Encoding: chunked.

Symptoms

Symptoms

Large uploads (>1 MB) sent with Transfer-Encoding: chunked consistently receive 413 from the NGINX proxy. Smaller uploads succeed. Uploading directly to the Node.js backend (bypassing NGINX) succeeds for the same large payloads.

Observations

Observations

NGINX access logs show 413 responses for problematic requests; error log entries include 'client intended to send too large body' for some requests despite client_max_body_size set to 0 in the server block. Disabling http2 on the SSL listener makes the same uploads succeed through NGINX. Changing client_max_body_size had no consistent effect.

Already attempted

Already attempted

Set client_max_body_size 0 and then to larger explicit values; toggled proxy_request_buffering on/off; set proxy_buffer_size higher; tried proxy_http_version 1.1 in various locations; restarted nginx and node; captured request flows with curl --http2 and curl --http1.1. None of these reliably fixed the 413 while http2 stayed enabled.

Question

Question

Why do chunked, Transfer-Encoding uploads get rejected with 413 only when NGINX terminates TLS/http2? What safe, reversible configuration or workaround lets the proxy accept chunked uploads without disabling http2 or requiring clients to set Content-Length?

COMMUNITY RESPONSES

Verified community troubleshooting

0 replies

No answers yet..

Showing 0 of 0 community responses
AI DIAGNOSTICS

Incident analysis

Updated 4w ago• Trouble ID

Most likely causes

NGINX mishandling HTTP/2 request body when TLS/http2 is terminated at the proxy (http2-to-http1 conversion buffering or a bug/regression) 70%
proxy_request_buffering default behavior causes NGINX to enforce size limits before body is fully received or reassembled 50%
Backend (Node.js) returning an early 413 or closing connection that NGINX translates to 413 (less likely because direct requests succeed) 20%

Summary

Behavior points to an interaction between HTTP/2 TLS termination and NGINX's buffering/request-size logic: when NGINX terminates http2 it reassembles frames and may buffer the request body differently before proxying to an HTTP/1.1 backend. If the body isn't available or NGINX rejects the pre-read body against its internal limits, it can return 413 even if client_max_body_size appears permissive. Some known patterns: proxy_request_buffering, proxy_http_version, and http2-to-http1 conversion bugs/regressions can cause chunked bodies to be treated as too large or unavailable at the time NGINX enforces limits.

Suggested Fixes

Diagnostic step 1
Reproduce the failure locally with curl --http2 -v and capture request/response headers to confirm where 413 originates.
Diagnostic step 2
Temporarily set proxy_http_version 1.1 and add proxy_set_header Connection "" for the proxy_pass to allow transparent chunked forwarding; verify uploads succeed.
Diagnostic step 3
Try turning proxy_request_buffering off on the location handling uploads (proxy_request_buffering off) and test again.

Continue troubleshooting

Matched from the title, description and tags