413/414 Request URL/Entity Too Large Error Nginx
what is 413/414 request URL/entity too large issue?
Ever tried to upload a huge file or send a very large payload in the request?
If yes, you must have received status code 413 from nginx saying that the “request entity is too large for nginx to handle”.
The reason for this error response is because of the “client_max_body_size” parameter in the nginx configuration.
Web servers keep a limit on the maximum size of the request that can be sent to them. This is handled using client_max_body_size parameter. That is because, as mentioned in this stack exchange answer and I quote —
If you configure “
client_body_max_size" to a large value, then you are putting your server in the same scenario as by 2013 when Django allowed users to use a very long password forcing Django (rather the server where it is hosted) to perform very expensive hash calculations leading, as you may guess, to a denial-of-service attack against the whole Django’s authentication framework.
In nginx documentation, By default the value of
client_body_max_size is 1 MiB.
If it is a requirement to change
client_body_max_size in nginx configuration, It can be done in the following way:
- Run the the following command to edit
- Add the following line at the top of
locationcontext to edit the size and then save and close the file.
nginxusing the following command.
sudo service nginx restart
There you go, the maximum permitted request size in nginx configuration has been changed.
HTTP 414 request-URI too large
414 URI Too Longresponse status code indicates that the URI requested by the client is longer than the server is willing to interpret.
Talking in terms of “Nginx” web server. This can also be handled in the similar manner as HTTP 413 error. To handle this we have to modify large_client_header_buffers parameter in the server configuration.
As mentioned in the documentation, default size of
large_client_header_buffers is 8 KB.
This way you errors pertaining to max size of request payload or request URI can be handled.
If you enjoyed this tutorial, please click the 👏 button and share to help others find it! Feel free to leave a comment below.