The Fix
Add one line to the server block of the site, sized for the largest upload you expect:
server {
server_name example.com;
client_max_body_size 64m;
# the rest of the block
}sudo nginx -t
sudo systemctl reload nginxThe server block is in /etc/nginx/sites-available/ on Debian and Ubuntu and in /etc/nginx/conf.d/ on AlmaLinux and Rocky Linux. Reload rather than restart: if the test failed, a reload leaves the running server untouched, while a restart with a broken file takes the site down.
What the Limit Does
client_ caps the size of the request body, which is where uploaded files and posted forms travel. The default is 1m, one megabyte. When a request body is larger, Nginx refuses it with 413 and the application never sees it. The Nginx documentation warns that browsers cannot always display this error correctly, so an upload may fail with a generic message, but the access log records the 413:
sudo grep '" 413 ' /var/log/nginx/access.log | tailWhere to Put It
- http block: in
/etc/nginx/nginx.conf, the value for every site. - server block: one site.
- location block: one path, such as an upload endpoint.
The most specific value wins, so a small value left in a location overrides a large one in the server block. Find every existing setting:
sudo nginx -T | grep -n client_max_body_sizeRaising the limit only where uploads arrive keeps the small default for everything else:
location /upload/ {
client_max_body_size 200m;
proxy_pass http://127.0.0.1:3000;
}Units are k, m, and g. A value of 0 turns the check off; avoid that on a public site.
PHP Limits Behind Nginx
With PHP-FPM, PHP has two limits of its own:
- upload_
max_ the largest single file; the default is 2M.filesize: - post_
max_ the whole request body; the default is 8M. Keep it larger than the file limit.size:
upload_max_filesize = 64M
post_max_size = 72MSet them in the php.ini that PHP-FPM reads: /etc/php/8.3/fpm/php.ini on Debian and Ubuntu (8.3 on Ubuntu 24.04, 8.4 on Debian 13, 8.5 on Ubuntu 26.04), and /etc/php.ini on AlmaLinux and Rocky Linux. Then restart PHP-FPM: sudo systemctl restart php8.3-fpm, or php-fpm on the Red Hat family. The command-line PHP reads a different file, so php -i may show other values; see how to install PHP on Ubuntu.
A request over the PHP limits does not cause a 413. A file over upload_ is dropped with an upload error, and a body over post_ leaves the posted fields and files empty, so the application reports an empty upload or a failed form.
Slow and Large Uploads
A big file over a slow connection can also hit time limits. client_ in Nginx, 60 seconds by default, applies between two reads of the body, so a steady upload is not cut off. In PHP, max_ limits how long a script may spend parsing input; its default, -1, means the max_ value is used. Very large transfers are often better done over SFTP than through a web form.
Every Layer Has a Limit
If Nginx passes requests to an application, the application may have its own body limit, such as the body parser of a Node.js framework. A CDN or load balancer in front can set a limit too. Raise the value on each layer the upload passes through, from the outside in. Other request-size errors are explained in 431 Request Header Fields Too Large.
Confirm the Fix
Upload a file a little below the new limit through the site's own form, then look at the end of the access log:
sudo tail -n 5 /var/log/nginx/access.logThe upload request should now show 200, or the redirect the form sends after success, instead of 413. A file above the limit should still get 413, which shows that the limit is in force. If the request passes Nginx but the file never arrives, the PHP or application limit is the one left to raise.
Updated:
Linux VPS with Full Root Access
MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.
More Guides
No Limits on Service or Support
You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

- 100% customer satisfaction goal
- Our own hardware
- 24/7 ticket and email support
- 4 countries with locations