Laravel file upload returns 413 behind nginx
413 Request Entity Too LargeShort answer
A 413 means a limit refused the request body before Laravel could use it. nginx rejects bodies over client_max_body_size, which is 1m by default. PHP has its own two limits, upload_max_filesize and post_max_size. Raise the nginx value first, reload nginx, then keep post_max_size larger than upload_max_filesize.
Fix it fast
1Find out which cause you have
Send a test file just over 1 MB straight to the route and read the status line. A 413 with an nginx page means the nginx limit; a normal Laravel response (a validation message) means the PHP or Laravel limits.
head -c 2000000 /dev/zero > /tmp/test-2mb.bin curl -i -F "file=@/tmp/test-2mb.bin" https://example.com/upload2Match what you see, then jump to its fix
- 1
The 413 is returned by nginx, so the request does not reach Laravel and nothing new appears in its log.nginx client_max_body_size is still at its 1m defaultFix - 2
You raised client_max_body_size, but the 413 is unchanged.The limit sits in a different block than the one that serves the routeFix - 3
nginx passes the request, but the upload still fails; the PHP defaults are 2M for a file and 8M for the whole POST.PHP's upload_max_filesize or post_max_size is lower than the fileFix
- 1
What does the error look like?
413 Request Entity Too Large413 Content Too Large
Cause 1 of 3
nginx client_max_body_size is still at its 1m default
1Check
Search the active nginx configuration for the directive. If nothing sets it, the default of 1m applies to every request body.
grep -R "client_max_body_size" /etc/nginx/2Fix
Set the directive to the largest upload you want to accept. It is allowed in the http, server and location contexts, so you can raise it only for the upload route.
server {
server_name example.com;
location /upload {
client_max_body_size 50m;
# ...usual fastcgi_pass to php-fpm...
}
}3Verify
Reload nginx and repeat the test upload. The status should change from 413 to whatever Laravel returns.
sudo nginx -s reload
curl -i -F "file=@/tmp/test-2mb.bin" https://example.com/uploadConfirmed by nginx.org
Cause 2 of 3
The limit sits in a different block than the one that serves the route
1Check
A value set in one server or location block does not reach another. Find every block that can answer this URL, including a second nginx or proxy in front of the app.
grep -R -n "client_max_body_size\|server_name\|location" /etc/nginx/sites-enabled/2Fix
Put the directive in the block that actually handles the upload URL, or in the http context if every site may take large bodies. A value in a location block applies to that location only.
http {
client_max_body_size 50m;
}3Verify
Reload nginx; the master process applies the new configuration to fresh workers. Then upload again.
sudo nginx -s reloadConfirmed by nginx.org
Cause 3 of 3
PHP's upload_max_filesize or post_max_size is lower than the file
1Check
Print the limits from the PHP build that serves the site. FPM can use a different php.ini than the CLI, so check the FPM file.
php --ini
php -i | grep -E "upload_max_filesize|post_max_size|max_file_uploads"2Fix
Raise both values in the php.ini that php-fpm loads. post_max_size has to be larger than upload_max_filesize, and the manual advises memory_limit above post_max_size. These settings cannot be changed with ini_set() at runtime.
; php.ini used by php-fpm
upload_max_filesize = 50M
post_max_size = 55M3Verify
Restart php-fpm, then read the values back through a request or a phpinfo page that runs under FPM.
sudo systemctl restart php8.3-fpmConfirmed by php.net
How do I stop it coming back?
- Decide the real maximum upload size once and set the nginx and PHP values together, with post_max_size a little above the file limit.
- Add the same size to Laravel's validation rule for the file so users get a clear message instead of a bare error page.
- Keep a test file just over the limit in your deploy checklist and upload it after every server change.
- For very large files, upload straight to object storage with a signed URL instead of through PHP.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- Spotless LaundryAn on-demand laundry app: Flutter on a Laravel back end, with Firebase for live updates.
- EZ EstimaterConstruction quoting and job tracking for contractors, on a Laravel and Firebase stack.
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
Related fixes
Back end
Livewire uploads work locally but fail behind nginx on the server
$_POST and $_FILES are empty (PHP discards a body over post_max_size)
Three separate limits stop a large upload, and a local dev server hides two of them.
3 causes, each with a fixBack end
Laravel routes return 404 or throw NotFoundHttpException
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
A 404 means Laravel found no route for that URL, or the request never reached Laravel at all.
3 causes, each with a fixBack end
PHP stops the script after 30 seconds
Symfony\Component\ErrorHandler\Error\FatalError: Maximum execution time of 60 seconds exceeded
PHP ends a script that runs past max_execution_time (30 seconds by default for web requests).
5 causes, each with a fixBack end
Composer says the gd extension is missing on a Laravel project
composer install or composer update stops on a package that requires ext-gd
Composer refuses to install a package that requires ext-gd when the PHP binary running Composer has no GD extension.
4 causes, each with a fixBack end
Why a Filament panel feels slow on a Laravel server
The panel is fast on a small demo and slow once there are many resources, pages and widgets
A slow Filament panel on a server is most often running without the production caches.
3 causes, each with a fixBack end
Intervention Image will not save the file in a Laravel app
Can't write image data to path (/var/www/app/public/uploads/photo.jpg)
Intervention Image writes straight to a file path.
3 causes, each with a fix