Diagnosing NGINX HTTP 413: Locate the Rejecting Layer and Apply a Scoped Fix
A diagnostic guide to identify whether NGINX or an upstream service generated an HTTP 413, locate the effective request-body limit, and apply a narrowly scoped fix without increasing global exposure.
17 Nov 2026, 17:12 UTC

The Problem: 413 Without Context
An HTTP 413 Payload Too Large response tells you a request body exceeded a limit, but it does not tell you which component enforced that limit. In a typical stack — load balancer, NGINX, application server — any layer can return 413. Treating the status code as a single problem leads to wasted debugging: raising client_max_body_size in NGINX when the upstream application rejected the request, or adjusting the application when a front-end proxy already blocked the payload.
Takeaway: Identify the rejecting layer first using response body, NGINX logs, and an access-log format that includes $upstream_status. Then apply the fix only at that layer, scoped to the narrowest matching context.
Recognizable Condition
A client receives 413 when uploading a file or posting JSON. The response may contain an NGINX default error page, a custom error page, or the upstream application's own error format. Intermittent 413s on the same endpoint suggest chunked transfer encoding, multiple proxy hops, or a limit that sits close to the actual payload size.
Cause and Diagnostic Table
| Observation | Likely Source | Primary Evidence |
|---|---|---|
Response body matches NGINX default error page (<center><h1>413 Request Entity Too Large</h1></center>) |
NGINX client_max_body_size exceeded |
NGINX error log shows client intended to send too large body; access log $status = 413, $upstream_status = "-" |
| Response body contains application-specific JSON or HTML | Upstream application (e.g., Node.js, Java, Go, PHP-FPM) | NGINX access log $upstream_status = 413; application logs show request-size rejection |
| 413 appears only for certain clients or payload sizes near a threshold | Interaction of Content-Length vs chunked encoding, or multiple proxy layers each with their own limit |
Compare $request_length (includes headers) with declared Content-Length; check each hop's limit |
413 persists after raising client_max_body_size and reloading NGINX |
Limit enforced upstream, or NGINX configuration not applied to the matching location | Verify effective config with nginx -T; check upstream service config |
Ordered Checks
1. Reproduce Safely with a Test Payload
Create a non-sensitive test file that approximates the failing payload size. Use curl to send it while capturing the full response and request metadata.
# On a host that can reach the NGINX endpoint
# Replace with your actual endpoint and target size
TEST_SIZE=10485760 # 10 MiB
dd if=/dev/urandom of=/tmp/testpayload bs=1 count=$TEST_SIZE 2>/dev/null
# Send with Content-Length (default)
curl -v -X POST -H "Content-Type: application/octet-stream" \
--data-binary @/tmp/testpayload \
https://example.example/upload 2>&1 | tee /tmp/curl-cl.out
# Send with chunked transfer encoding (no Content-Length)
curl -v -X POST -H "Content-Type: application/octet-stream" \
-H "Transfer-Encoding: chunked" \
--data-binary @/tmp/testpayload \
https://example.example/upload 2>&1 | tee /tmp/curl-chunked.out
Record: HTTP status, response body, request URI, whether Content-Length or Transfer-Encoding: chunked was used, and the exact byte count sent. Run from a staging or development environment; avoid production traffic.
2. Inspect the Effective client_max_body_size
Dump the full running configuration and locate the directive in the matching server and location blocks. Nested directives override inherited values; the default is 0 (no NGINX body-size limit).
# Run as root or with sudo on the NGINX host
nginx -T 2>/dev/null | grep -n -A2 -B2 'client_max_body_size'
# Or view the full merged config for the relevant server
nginx -T 2>/dev/null | awk '/server_name example\.example/,/^}/'
Note the value at each level: http, server, location. A location /upload block with client_max_body_size 5M; overrides a server-level 20M. If the directive is absent entirely, NGINX imposes no limit.
3. Compare Actual Payload with the Effective Limit
Content-Length declares the body length; $request_length in the access log includes headers and request line. Neither is a perfect body measurement. For chunked requests, Content-Length is absent. Use the test payload's known byte count as ground truth.
Example access-log format (add to http or server block, then reload):
log_format diagnostics '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" '
'$request_length $content_length $upstream_status';
access_log /var/log/nginx/access.log diagnostics;
After reload, reproduce the request and examine the log line. If $status = 413 and $upstream_status = "-", NGINX generated the 413. If $upstream_status = 413, the upstream generated it.
Fixes Tied to Findings
NGINX Generated the 413
Raise client_max_body_size only in the narrowest matching server or location block. Avoid a global increase in http context.
# Example: only the upload endpoint needs a larger limit
server {
server_name example.example;
client_max_body_size 10M; # default for most routes
location /upload {
client_max_body_size 50M; # scoped to known upload route
proxy_pass http://app_upstream;
}
}
Validate and reload:
nginx -t
nginx -s reload
Risk: A very large limit increases disk usage for temporary body files (controlled by client_body_buffer_size and client_body_temp_path), memory pressure, and upstream workload. Prefer a bounded, location-specific policy.
Upstream Generated the 413
Change the upstream service's own request-size limit. Examples:
- Node.js (Express):
app.use(express.json({ limit: '50mb' })); - Java (Spring Boot):
spring.servlet.multipart.max-request-size=50MB - Go (net/http):
http.MaxBytesHandler(handler, 50<<20) - PHP-FPM:
post_max_sizeandupload_max_filesizeinphp.ini
After changing the upstream, restart or reload that service. Do not modify NGINX client_max_body_size for this case.
Multiple Proxy Layers
If a front-end load balancer (AWS ALB, Cloudflare, HAProxy) sits before NGINX, each layer has its own limit. Check each layer's configuration and logs. The 413 may originate at the first layer that sees the request. Apply the fix at that layer, then verify the request reaches the next hop.
Escalation Criteria
Escalate to a broader investigation when:
- The 413 is emitted before the request reaches NGINX (check load balancer / WAF logs).
- The 413 persists after a verified
nginx -tand reload with the corrected configuration. - The request size is demonstrably below the configured limit (use the test payload's exact byte count).
- Multiple NGINX or proxy hops exist and the rejecting layer cannot be isolated.
When escalating, preserve sanitized request metadata (method, URI, headers without secrets), relevant NGINX error and access logs, upstream application logs, and the exact matching configuration context from nginx -T.
Verification Checklist
- In staging, send bodies just below, exactly at, and just above the effective limit. Confirm which sizes succeed and which return 413.
- After any change, run
nginx -t, reload withnginx -s reload, and repeat the same request while checking error and access logs. - For proxied requests, compare
$upstream_statusin NGINX logs with application logs to ensure no second 413 remains. - Test both
Content-Lengthand chunked uploads, and repeat through every proxy or NGINX hop in the production path.
Limitations
This guide covers request-body limits only. Response-size limits (proxy_max_temp_file_size, upstream response buffering) are separate. client_body_buffer_size controls when NGINX spills the body to a temporary file; it is not a total upload limit. Custom error pages can obscure the rejecting component — rely on logs and layer-by-layer status comparison rather than page appearance alone.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.