Linux  ·  medium  ·  Web, PHP & databases

413 Request Entity Too Large, or uploads fail silently

A size limit is being hit at one of three separate layers, and all three have to agree.

What you see

Uploads over a certain size fail — sometimes with a 413, sometimes with a blank page or a silent failure that the application reports as an empty file.

What is actually wrong

nginx, PHP and the application each impose their own limit. The smallest wins, and the error you see depends on which one it was.

Codes and articles

413 Request Entity Too Largeclient intended to send too large bodyupload_max_filesizepost_max_size

The fix

Raise every limit in the chain
Root shell25 minuteslow riskreversible

Uploads fail above a size.

  1. Read the current values at each layer.

    Shell
    grep -rn client_max_body_size /etc/nginx/ 2>/dev/nullphp -i | grep -E 'upload_max_filesize|post_max_size|memory_limit|max_file_uploads'

    Setting one and not the others produces a different failure at the next layer down, which is why this often takes three attempts. Reading all three first makes it one change.

  2. Raise the nginx limit, in the server or location block that serves the upload path.

    Shell
    sudo sed -i '/http {/a\    client_max_body_size 64M;' /etc/nginx/nginx.confsudo nginx -t && sudo systemctl reload nginx
  3. Raise the PHP limits. post_max_size must be larger than upload_max_filesize, and memory_limit larger than both.

    Shell
    sudo sed -i 's/^upload_max_filesize.*/upload_max_filesize = 64M/; s/^post_max_size.*/post_max_size = 72M/; s/^memory_limit.*/memory_limit = 256M/' /etc/php/8.2/fpm/php.inisudo systemctl restart php8.2-fpm
  4. Check the application's own limit — most content management systems have one in their settings as well.

  5. Raise the timeouts to match. A 64MB upload on a slow connection can exceed the read timeout and fail as a 504 instead.

    Shell
    grep -rn 'client_body_timeout\|fastcgi_read_timeout' /etc/nginx/
Confirm it workedA file just under the new limit uploads successfully.
Shell
php -i | grep -E 'upload_max_filesize|post_max_size'curl -sI -X POST -F file=@test.bin http://localhost/upload | head -3
If you need to undo itRestore the previous values in nginx.conf and php.ini, then reload both.

Where this stops. This write-up was written and checked by hand. It says what each step changes, how to confirm it worked and how to reverse it, and anything destructive is flagged before you reach it. If it does not match what your machine is doing, search the Support Centre for the exact code or message — and when something needs a person, get in touch.