Nginx HTTP:413 Request Entity Too Large solution

  • 2020-05-09 19:59:21
  • OfStack

An overview of the

Today, I encountered a problem and the following error occurred when uploading pictures in the PHP program: HTTP:413 Request Entity Too Large.

Development environment: CentOS + Nginx + PHP + MySql

The solution

To solve this problem, you need to adjust the configuration of PHP and Nginx parameters according to the size of the uploaded data file.

Configuration PHP

The default upload size limit for PHP is 2M. If you exceed 2M, you will need to modify the parameters in the PHP configuration file php.ini.


post_max_size = 8M (the maximum limit for form submissions, which does not limit the size of a single file to be uploaded, but the data submitted for the entire form.)
upload_max_filesize = 2M (maximum limit of single file uploaded)
Need to make sure that post_max_size >= upload_max_filesize So the former is not less than the latter.
After the modification 1 Need to restart php-fpm .

Configuration Nginx

In addition to modifying the php configuration, you also need to modify the nginx configuration file nginx.conf.


client_max_body_size 30M;

Among them, 30M can be set according to the required upload file size.
After modification 1 must be reloaded to nginx(service nginx restart).

conclusion

I solved several small problems today, and recorded them one by one
You don't have to make much progress. One point a day


Related articles: