Nginx 413: Request Entity Too Large
An upload fails with '413 Request Entity Too Large'. Nginx has a size limit on request bodies, and your file blew past it. Here's the one directive to change — and why the app never even saw the request.
A file upload dies and the browser shows:
413 Request Entity Too Large
This one is entirely Nginx's doing, and your application never even got the request. Nginx caps the size of a request body with a directive called client_max_body_size — default 1 MB. Anything bigger is rejected at the door with a 413, before it's ever proxied to your app. So no amount of changing app settings will help.
Confirm it in the log
tail -f /var/log/nginx/error.log
# client intended to send too large body: 5242880 bytes
That line names the exact size that tripped the limit.
The fix: raise client_max_body_size
Set it to a ceiling that fits your largest legitimate upload. You can place it in the http, server, or a specific location block — narrowest scope is best:
server {
# allow uploads up to 50 MB on this site
client_max_body_size 50m;
location /upload {
proxy_pass http://127.0.0.1:8000;
}
}
Then test and reload — never skip the test:
nginx -t && systemctl reload nginx # -t catches typos before they take the site down
Set the limit to a real number, not "as high as possible".
client_max_body_size 0disables the check entirely, which invites someone to exhaust your disk or memory with a giant upload. Pick a value slightly above your biggest genuine file.
Don't forget the app's own limit
Nginx is only the first gate. Your framework often has its own body-size cap (Django's DATA_UPLOAD_MAX_MEMORY_SIZE, PHP's upload_max_filesize). If uploads still fail after fixing Nginx, raise the matching limit in the app too.
The checklist
- 413 = Nginx rejected the body before your app saw it.
- Confirm with "too large body" in the error log.
- Set
client_max_body_sizeto a sane ceiling in the right block. nginx -t && systemctl reload nginx.- Raise the framework's upload limit to match.
Stop reading, start building
This pairs with a hands-on BytExplorer course — do it on your own machine and actually keep the skill.