DEV Community

Daniele Michelin
Daniele Michelin

Posted on Originally published at daniele-michelin.com

HTTP 413 Request Entity Too Large: nginx fix

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_size is 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_filesize and post_max_size are 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
Enter fullscreen mode Exit fullscreen mode

Find 413 cases in the log

grep 'too large body' /var/log/nginx/error.log | tail -n 10
Enter fullscreen mode Exit fullscreen mode

Check the PHP-FPM limits (not the CLI ones)

grep -rE 'upload_max_filesize|post_max_size' /etc/php/8.3/fpm/
Enter fullscreen mode Exit fullscreen mode

What actually helps

  1. Set client_max_body_size 10G; in the right server or location block (0 disables the check).
  2. Test and reload: nginx -t && systemctl reload nginx.
  3. 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.

Top comments (0)