🚀 20% OFF for new customers on Linux and Windows servers! Code: ILK20  |  Order Now →
build Troubleshooting & Automation

How to Fix Nginx 413 Request Entity Too Large Error (Step by Step)

If you encounter a 413 error while uploading files in Nginx, you need to change the client_max_body_size setting. Here are step-by-step solutions.

person
Editör
(Updated: Jul 28, 2026) schedule 3 min read visibility 11 views

If you are using Nginx as your web server, you might have encountered the 413 Request Entity Too Large error when trying to upload large files. This error typically occurs when you exceed Nginx's default client_max_body_size limit of 1 MB. For example, you might see this error when uploading a 10 MB PDF or a 50 MB video. Fortunately, the solution is quite simple: just configure the relevant setting.

Understand the Source of the Error

Nginx checks the body size of client requests. If the size exceeds the client_max_body_size value, it immediately returns a 413 error. This setting can be defined in Nginx's main configuration file nginx.conf, in a specific server block, or in a location block. Depending on where it is defined, you may need to change the setting accordingly.

Change the client_max_body_size Setting

First, open the Nginx configuration file. It is usually located at /etc/nginx/nginx.conf or /etc/nginx/sites-available/default. After opening the file with a text editor, look for a line like this:

client_max_body_size 1M;

If the line does not exist, you need to add it. For example, to allow file uploads up to 100 MB, change the line to:

client_max_body_size 100M;

Setting Within a Server Block

If you want to change the setting only for a specific site, add the same line inside the relevant server block. For example:

server { listen 80; server_name hosting.example.com; client_max_body_size 100M; ... }

Setting Within a Location Block

For even more specificity, you can set different limits for specific URL paths. For example, to allow 200 MB in the /uploads directory:

location /uploads { client_max_body_size 200M; }

Test and Restart Nginx

After making changes to the configuration file, check for any syntax errors:

sudo nginx -t

If the test is successful, restart Nginx:

sudo systemctl restart nginx

Now you can try uploading files again.

Compatibility with PHP-FPM

If you are running a PHP-based application, remember that PHP also has its own upload limits. Check the upload_max_filesize and post_max_size settings in your php.ini file. It is good practice to set them to the same values. For example:

upload_max_filesize = 100M post_max_size = 100M

After making changes, remember to restart PHP-FPM.

Final Checks and Tips

In some cases, if you are using a reverse proxy or CDN, they may have similar limits. Additionally, increasing the client_body_buffer_size setting can be beneficial for performance. However, keep in mind that very high values can strain server resources. Typically, values between 10 MB and 100 MB should suffice. After applying these settings, you should no longer see the 413 error.

Share This Article

Related Posts