How to Fix Nginx Error 413 Request Entity Too Large
I'm a PHP web developer, so it's very common to have issues with LEMP stack. This time I want to share my experience on Nginx error code 413 - Request Entity Too Large.
Just as you might have guessed, the error message itself is pretty clear: we've sent a request which size is too large than the server has been configured with. By default, Nginx will allow maximum size 1 MiB of request.
To fix this issue, there are two configuration files need to be updated:
On Nginx, the
client_max_body_size directive assigns the maximum accepted body size of client request and specify the line Content-Length in the header of request. If the size is greater the given one then the client get the error "Request Entity Too Large".
We will update our main Nginx configuration file
nginx.conf. On Ubuntu or any Ubuntu based distribution, the file located at
/etc/nginx/nginx.conf. If you have other distribution, you can check
You can edit the file using any of your favorite editor. I'll use
vi as an example.
$ sudo vi /etc/nginx/nginx.conf
Add this line to your prefered context. In this example, I put it globally.
# set maximum client body size to 10M
You can set the context where you want the configuration to take effect:
httpto set it globally
serverto set it at related host
locationto set it at specific URI
Save the configuration file and exit. Next step is reload nginx service. On your shell, type this command:
$ sudo service nginx reload
On other distribution, you could try:
$ sudo /usr/local/nginx/sbin/nginx -s reload
$ /sbin/nginx -s reload
On Ubuntu based PHP-FPM configuration file, by default it has these limitations:
post_max_size = 8M
upload_max_filesize = 2M
We'll need to update those limitations. Open your
php.ini configuration file. In my case, it's on
$ sudo vi /etc/php/7.2/fpm/php.ini
Update those lines:
post_max_size = 10M
upload_max_filesize = 10M
Save the file and then reload PHP-FPM.
$ sudo service php7.2-fpm reload
I hope that you now know how to fix Nginx error 413 - Request Entity Too Large on Linux. If you run into any issues or have any feedback feel free to drop a comment below.