How to Fix 413 Request Entity Too Large Error in Nginx (Quickly)
The 413 request entity too large error on an Nginx web server occurs when a client attempts to upload a file (such as an image, a WordPress plugin, or a heavy backup) whose size exceeds the maximum upload limit configured in the web proxy settings.
Quick Diagnostics
nginx.conf: client_max_body_size 64M;upload_max_filesize = 64M in PHP configuration fileThe 413 request entity too large error on an Nginx web server occurs when a client attempts to upload a file (such as an image, a WordPress plugin, or a heavy backup) whose size exceeds the maximum upload limit configured in the web proxy settings.
Step-by-Step Solution
-
1
Step 1: Configure upload limit in Nginx
Open the global Nginx configuration file or the specific website server block configuration:
BASH# Open main Nginx configuration file sudo nano /etc/nginx/nginx.confInside the
http,server, orlocationblock, add or modify the following directive to increase the upload limit (for example, to 64 Megabytes):NGINX# Allow uploads up to 64MB client_max_body_size 64M; -
2
Step 2: Adjust PHP-FPM upload limits (if applicable)
If your website runs on PHP (such as WordPress, Drupal, or Laravel), you must align Nginx's limits with your PHP interpreter configurations:
BASH# Open the active PHP configuration file (adjust for your active PHP version) sudo nano /etc/php/8.2/fpm/php.iniFind and edit the following variables to match your Nginx configuration limits:
INIupload_max_filesize = 64M post_max_size = 64M memory_limit = 256M -
3
Step 3: Validate syntax and restart services
Test your Nginx configuration syntax for correctness before applying changes to production:
BASH# Test web server configuration syntax sudo nginx -t # Restart system services to apply the new configurations sudo systemctl restart nginx sudo systemctl restart php8.2-fpm
Prevention Advice
Recommended security practices:
- Do not set the
client_max_body_sizedirective to0(which disables size checking completely). Configuring an infinite upload limit exposes your Nginx web server to Denial of Service (DoS) attacks, allowing malicious actors to saturate your system storage by continuously uploading massive files.