How to fix 413 request entity too large error on Nginx

0
2653

In the process of installing a new webserver such as adding a plugin, theme or upload a large image file, you will often encounter 413 Request Entity Too Large error.

Reason
Because the Web Server Nginx and PHP limit the size of the file upload to the server. This error occurs even when you use phpmyadmin to restore the website.

To handle this error you have to configure both on Nginx and PHP-FPM.

Edit configuration on Nginx
SSH to the server find the nginx configuration file with /etc/nginx/nginx.conf

Then add the below directive to http block {…}, server {…}, or location {…}.

client_max_body_size client 15M;

Server that is configured vhost then you add to block server for easy management.

The configuration on the file size up up to 15M max, usually theme or wordpress plugin is only about 10M or more than that a bit then.

Configure PHP-FPM 
For each operating system the path to the PHP configuration file is slightly different, you use the nano to open php.ini file.

Path on Ubuntu

nano /etc/php/7.0/fpm/php.ini

Path on CentOS

nano /etc/php.ini

You correct this value

upload_max_filesize = 15M
post_max_size = 15M

Take the change and restart nginx and php-fpm

#nginx
systemctl restart nginx

# php-fpm
systemctl restart php7.0-fpm

There are some other basic errors that you should also pay attention when installing new VPS:

Good luck!

LEAVE A REPLY

Please enter your comment!
Please enter your name here