How to Fix Nginx 413 Request Entity Too Large for Image & Video Uploads
You try to upload a big image or video and Nginx responds with: 413 Request Entity Too Large
nginx This means Nginx rejected the request before PHP or your app (Laravel, WordPress, etc.) ever saw it. The upload is simply bigger than Nginx is willing to accept.
Let’s fix that safely.
1. The key setting: client_max_body_size
Nginx controls max request size with client_max_body_size. If it is missing, the default is usually 1 MB. That is tiny for modern uploads, so large images or videos will be blocked.
You can set it in:
nginx.conf(global)- Inside an
http,server, orlocationblock
Example, for a single site:
server {
server_name example.com;
client_max_body_size 64M;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
}
Choose a size that fits your needs, like 20M, 64M, 100M, or more for big video uploads.
2. Reload Nginx after changing config
After editing the config file:
sudo nginx -t
If it says syntax is ok, reload:
sudo systemctl reload nginx
or on some systems:
sudo service nginx reload
Now Nginx accepts larger requests.
3. Make sure PHP upload limits match
If you only change Nginx, PHP might still reject large uploads with errors like:
POST Content-Length of X bytes exceeds the limit of Y bytes
Check your php.ini (or .user.ini on shared hosting) and set:
upload_max_filesize = 64M
post_max_size = 64M
Rules of thumb:
post_max_size≥upload_max_filesize- Both should be ≤ Nginx
client_max_body_size
After editing, restart PHP-FPM:
sudo systemctl restart php8.3-fpm
(adjust version to your PHP version).
4. Put the directive in the right place
For per-site limits, use the server block for that domain:
server {
server_name media.example.com;
client_max_body_size 200M;
...
}
If you put client_max_body_size inside a location that does not match your upload URL, Nginx will still use the low default and return 413.
For a global setting, you can place it in the http block in nginx.conf:
http {
client_max_body_size 64M;
...
}
5. Example for WordPress / Laravel uploads
WordPress
Uploads typically go through /wp-admin/admin-ajax.php or /wp-admin/media-new.php. A simple per-site config:
server {
server_name example.com;
root /var/www/example.com/public;
client_max_body_size 64M;
location / {
try_files $uri $uri/ /index.php?$args;
}
}
Laravel
If your app handles uploads at /upload or through a controller, the same pattern applies:
server {
server_name app.example.com;
root /var/www/app/public;
client_max_body_size 64M;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
}
The app will then just see a normal file upload within PHP limits.
6. Shared hosting or panel-based servers (Plesk, cPanel, CyberPanel)
If you do not edit Nginx by hand:
- Look for an option like Client Max Body Size, Upload size, or Nginx directives in your panel.
- Many panels let you paste extra directives per domain, for example:
client_max_body_size 64m; - For PHP limits, change
upload_max_filesizeandpost_max_sizein the panel’s PHP settings.
7. Troubleshooting: still getting 413
If you still see 413 after changes:
- Confirm you edited the correct vhost file for that domain.
- Run
nginx -T | grep client_max_body_sizeto see what values are actually active. - Clear any reverse proxy cache or restart any front-facing proxy in front of Nginx (less common).
- Make sure there are no older
client_max_body_sizedirectives with smaller values overriding your new one in a more specific block.
8. Quick checklist
When Nginx responds with 413 Request Entity Too Large for uploads:
- Set
client_max_body_sizeto a higher value (for example 64M) in the rightserverorhttpblock. - Reload Nginx after testing config with
nginx -t. - Increase
upload_max_filesizeandpost_max_sizein PHP to the same or slightly lower value. - Restart PHP-FPM so new limits apply.
- For control panels, use their interface to adjust Nginx and PHP settings instead of manual files.
With Nginx and PHP aligned on upload size, images and videos will upload successfully without the 413 error.