When you are using Nginx as a reverse proxy for Apache (or other web services) you may face this common HTTP issue: Nginx 413 Request Entity Too Large Error
Why does Nginx 413 Request Entity Too Large error happens?
The common scenario for this error is when you are running Nginx as front end server for a backend server like Apache, NodeJS or other services.
Then, your app tries to upload images, pdf or text files with up to 2MB or even more, and then the following error appears at the screen:
Nginx 413 Request Entity Too Large
The simple explanation for this Nginx 413 Request Entity Too Large error is that it shows up when a visitor sends too much data in the HTTP request. The fix is pretty simple in fact, just change one Nginx directive inside Nginx’s main configuration file, as you see below.
client_max_body_size is the directive in charge of setting the the max accepted body size of client requests. If the size is greater than the one set inside the client_max_body_size variable, then you get that Nginx 413 error in your screen.
If you are going to tweak this variable, let’s learn a little bit more about it:
Syntax Usage: client_max_body_size size;
Default on Nginx installations: client_max_body_size 1m;
Nginx Context blocks where you can use it: http, server, location
client_max_body_size size determines the max allowed size of the client request body, this is specified at the ‘Content Lenght’ field in your website headers. The Nginx 413 (Request Entity Too Large) error comes to the screen when the size exceeds the configured value, then the HTTP 413 error is returned to the client.
On your Nginx logs this also can be seen pretty similar to this:
2016/09/16 23:10:47 [error]: *10 client intended to send too large body: 1121268 bytes, client: 184.108.40.206, server: nixcp.com, request: "POST /wp-admin/update.php?action=upload-theme HTTP/1.1", host: "nixcp.com", referrer: https://nixcp.com/wp-admin/theme-install.php?upload
How can I fix HTTP 413 Request Entity Too Large error?
nano -w /etc/nginx/nginx.conf
If it is not already there, add this variable:
Another more critical fix for this error: setting client_max_body_size to 0 disables checking of client request body size.
Restart Nginx to apply changes:
That’s all, at this time your request entity too large nginx error should be fixed.