While working on web applications, you might have encountered the error. 413 Payload Too Large (previously known as 413 Request Entity Too Large). This error usually appears when a user tries to upload a file or send a request that exceeds the server’s allowed size limit. This article will explain what the 413 error means, why it happens, and how to fix it across different applications, including NGINX, Apache, PHP, Cloudflare, and other popular application frameworks.
What Does the 413 Error Mean?
The 413 error is an HTTP status code that indicates that the request was rejected because it exceeds the server’s configured limits. This usually occurs during:
• File uploads (images, videos, PDFs, etc.)
• Large JSON POST requests (common in APIs)
• Multipart form submissions
This issue can occur at different layers in your stack—at the web server (like NGINX or Apache), application layer (Node.js, PHP, Python), or even a proxy/load balancer, such as Cloudflare.
How to Fix the 413 Error
Let’s review how to resolve this error based on your web server or application.
Fixing 413 Error in NGINX
If your server runs NGINX, you can fix this error by increasing the client_max_body_size directive, which defines the maximum allowed size for client request bodies.
You’ll need to increase this value if you encounter the 413 error. Open your NGINX configuration file, which is usually located at:
/etc/nginx/nginx.conf
Or within a specific site configuration inside /etc/nginx/sites-available/.
Add or update the following directive inside the http, server, or location block:
client_max_body_size 50M;
This sets the maximum upload size to 50 MB.
After saving your changes, reload NGINX with the command:
sudo systemctl reload nginx
This change should resolve the 413 error caused by large uploads.
Fixing 413 Error in Apache
The LimitRequestBody directive controls the maximum allowed request size if you use Apache.
You will need to modify the Apache Configuration, edit the main configuration file that can be found at:
sudo nano /etc/apache2/apache2.conf
Or update the .htaccess file for the specific directory:
LimitRequestBody 52428800
The size is in bytes—52428800 equals 50 MB.
Once you’ve made the change, restart Apache:
sudo systemctl restart apache2
And the changes should take effect after the Apache restart.
Fixing 413 Error in PHP
When using PHP, you must ensure your php.ini allows larger file uploads.
Find your php.ini file — usually located at /etc/php/8.x/fpm/php.ini or /etc/php/8.x/apache2/php.ini.
You can also use the php -i | grep ‘Configuration File’ command to find the php.ini file.
Update or add the following lines:
upload_max_filesize = 256M
post_max_size = 256M
These two values should equal or exceed the file size you’re trying to upload.
Then you can restart the service if you are using PHP-FPM. For PHP 8.3, you can use the
sudo systemctl restart php8.3-fpm
sudo systemctl restart nginx
If you are using mod_php with Apache, you can restart the Apache service with:
sudo systemctl restart apache2
Fixing 413 Error in Django
If you’re using Django, update the DATA_UPLOAD_MAX_MEMORY_SIZE setting in settings.py:
DATA_UPLOAD_MAX_MEMORY_SIZE = 52428800 # 50 MB
Ensure the web server (Gunicorn, uWSGI, etc.) is configured to handle larger requests.
Fixing 413 Error Behind Cloudflare
If you are experiencing this issue on Cloudflare, it could be due to Cloudflare’s upload limit on specific plans:
• Free and Pro plans: 100MB
• Business plan: 200MB
• Enterprise plan: Customizable
To handle larger files, consider bypassing Cloudflare for file upload
Best Practices to Avoid the 413 Error
• Validate file size client-side before uploading.
• Implement chunked uploads or background jobs for better performance and reliability.
• Monitor logs and error reports for failed requests with this 413 error or a similar error message.
Conclusion
The 413 Request Entity Too Large error is a common but easily fixable issue. Whether running NGINX, Apache, PHP, Django, or other applications, increasing the allowed upload size will usually resolve the error. Always test your configuration after changes. Need help adjusting your server configuration or resolving this error by increasing the server limit? Sign up for our monthly server management or per-incident server support, and let us know how we can help. Our Linux hosting experts are available 24/7 to assist you.