How to Fix NGINX 413 Request Entity Too Large Error

Problem

The problem arrives when client tries to send a request which is more than the default 1 MB in size, for example, uploading an image or downloading a plugin or something.  You will see the error in the logs 413 (Request Entity Too Large).

Solution

The solution is to increase the client request size body by the client_max_body_size parameter in nginx.conf file. Following is the description of the client_max_body_size parameter. The default value is 1MB and you can set this to an HTTP, server or location contexts.

Sets the maximum allowed size of the client request body, specified in the “Content-Length” request header field. If the size in a request exceeds the configured value, the 413 (Request Entity Too Large) error is returned to the client. Please be aware that browsers cannot correctly display this error. Setting size to 0 disables checking of client request body size.

To fix this simply edit the nginx.conf file (this will change to all servers and locations)


sudo vi /etc/nginx/nginx.conf

add the client_max_body_size to a value of your requirement in our case it was 12MB


client_max_body_size 12m;

In addition to that If you client is sending large requests, consider increasing the client_body_buffer_size to 16K

Sets buffer size for reading client request body. In case the request body is larger than the buffer, the whole body or only its part is written to a temporary file. By default, buffer size is equal to two memory pages. This is 8K on x86, other 32-bit platforms, and x86-64. It is usually 16K on other 64-bit platforms.

So our final configuration was


client_max_body_size 12m;

client_body_buffer_size 16k;

Save and exit the file

Restart NGINX server


sudo systemctl restart nginx

Hope this post helps you to resolve 413 error on NGINX.

Leave a Reply

Your email address will not be published. Required fields are marked *