Troubleshooting guide
413 Request Entity Too Large: how to raise the limit safely
A 413 means the request body was bigger than something along the path allows. There are often several limits in a row, and the smallest one wins.
3 min read10 sectionsUpdated
On this page
Where the limits live
- Nginx:
client_max_body_size, default 1 MB. - Kubernetes ingress-nginx: the
nginx.ingress.kubernetes.io/proxy-body-sizeannotation. - Apache:
LimitRequestBody. - PHP:
upload_max_filesizeandpost_max_size, and both must be large enough. - Node.js: body parser limits, such as Express's default of 100 KB for JSON.
- CDN: Cloudflare caps upload size by plan, 100 MB on Free and Pro.
Find the layer that refused
The error page format identifies it. Test around the limit with a generated file and compare results when you go through the CDN and directly to the origin.
# Create a 5 MB test file and post it
head -c 5242880 /dev/urandom > /tmp/5mb.bin
curl -si -X POST --data-binary @/tmp/5mb.bin https://example.com/upload | head -8
# Effective Nginx limit, including every included file
sudo nginx -T 2>/dev/null | grep client_max_body_size
# PHP limits
php -i | grep -E 'upload_max_filesize|post_max_size'Fixes
Scope the increase to the upload route:
location /upload { client_max_body_size 50m; proxy_pass http://app; }
Then reload with nginx -s reload after nginx -t. Set the same limit in the ingress annotation and in the application so each layer agrees. For very large files, stop passing them through your servers: issue a presigned URL and let the browser upload to object storage directly. Validate size on the client as well, so the user gets a clear message before waiting for an upload to fail.
Catch it automatically
A rising 413 count usually means a client started sending more than before, such as a phone camera with larger photos. Track it per route in APM and include the observed Content-Length in logs. Avoid setting limits to unlimited, as a huge body can exhaust disk or memory and turn one upload into an outage.
What is the default Nginx upload limit?
client_max_body_size defaults to 1 MB. Requests with larger bodies receive a 413.
I raised the limit, why do I still get 413?
Another layer has a smaller limit. Check the CDN, the ingress controller, the application framework and the language runtime in turn.
Should I set client_max_body_size 0?
That disables the check, which removes a basic protection against disk and memory exhaustion. Prefer an explicit limit on the routes that need it.
Check it now, free
- Website down checker: Is it down for everyone or just me? Check any site now.
Related reading
- 431 Request Header Fields Too Large: how to fix it: Fix 431 Request Header Fields Too Large: bloated cookies, Node.js header limits and localhost cookie build-up, with commands to measure real header size.
- 414 URI Too Long: causes and how to fix it: Fix 414 URI Too Long errors: redirect loops that grow the URL, huge query strings and large GET filters, with Nginx and Apache settings and better designs.
- 499 Client Closed Request in Nginx: what it means: What Nginx 499 Client Closed Request means: impatient clients, load balancer timeouts and slow backends, and how to tell a harmless 499 from a real outage.
- MySQL: Too many connections: Fix MySQL error 1040 Too many connections: check max_connections and current threads, find sleeping or leaked connections, size application pools.
- JavaScript heap out of memory: how to fix it in Node.js: Fix FATAL ERROR: JavaScript heap out of memory. Set --max-old-space-size correctly, handle build-time failures and find runtime leaks with heap snapshots.
- 429 Too Many Requests: what it means and how to fix it: 429 Too Many Requests explained: rate limits, the Retry-After header, backoff with jitter for clients, and how to set fair rate limits on your own API.
Watch your own site and services with VitalRix
Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.