A quick post today, NGINX is a go-to web server these days and we at DataNext prefer it as well, one of the reasons is ease of configurations and features like load balancing and more.
We had 413 Error in the past and solution is quite simple, recently we faced this error while migrating new application environment for one of our customers, so I thought it’s good idea to document it here.
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.
Cheers,
Zeeshan Baig
About DataNext
DataNext Solutions is US based system integrator, specialized in Cloud, Big Data, DevOps technologies. As a registered AWS partner, our services comprise any Cloud Migration, Cost optimization, Integration, Security and Managed Services. Click here and Book Free assessment call with our experts today or visit our website www.datanextsolutions.com for more info.