The request body (usually an upload) is larger than the limit nginx or a proxy in front of it allows – the request never reaches the application.
Common causes
-
client_max_body_sizeis not set; the nginx default is 1 MB. - The directive is in the wrong context or in a file that is not included.
- A second proxy in front (load balancer, Docker proxy, Cloudflare with 100 MB on the free plan) has its own limit.
- PHP limits
upload_max_filesizeandpost_max_sizeare too small (usually an application error rather than 413).
How to check it
Find the effective value in the loaded config
nginx -T 2>/dev/null | grep -n client_max_body_size Find 413 cases in the log
grep 'too large body' /var/log/nginx/error.log | tail -n 10 Check the PHP-FPM limits (not the CLI ones)
grep -rE 'upload_max_filesize|post_max_size' /etc/php/8.3/fpm/ What actually helps
- Set
client_max_body_size 10G;in the rightserverorlocationblock (0disables the check). - Test and reload:
nginx -t && systemctl reload nginx. - Raise the same limit on every proxy in front.
FAQ
Why doesn't changing php.ini help?
Because the 413 comes from nginx before PHP ever sees the request. Also, PHP-FPM uses a different php.ini than the CLI.
Is client_max_body_size 0 a good idea?
Only behind authentication. On public endpoints it allows arbitrarily large requests and makes simple resource attacks easy.
Full page with every command and the German/Italian version: daniele-michelin.com/en/errors/http-413-request-entity-too-large/
First published at daniele-michelin.com. The error lexicon covers HTTP, DNS, TLS, mail, database, PHP, nginx, systemd and Nextcloud, in German, English and Italian.
