PHP上傳文件大小限制的調整 Nginx 413 Request Entity Too Large

Nginx+php-fpm架構,遇到這個錯誤時:Request Entity Too Large 或 Nginx 413 Request Entity Too Large,須要作以下調整便可。php

一、修改配置一:Tune Nignx.conf setting:架構

# set client body size to 2M under http scope
client_max_body_size 2M;php-fpm

超時設置:
 post

send_timeout    60;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;

二、修改配置二:Tune php.ini settings:優化

;This sets the maximum amount of memory in bytes that a script is allowed to allocate
memory_limit = 32Mthis

;The maximum size of an uploaded file.
upload_max_filesize = 2Mcode

;Sets max size of post data allowed. This setting also affects file upload. To upload large files, this value must be larger than upload_max_filesize
post_max_size = 3Mip

 

三、修改配置三:優化php-fpm配置內存

php_admin_value[memory_limit] = 1224Mit

3/28 UPDATE:假設上傳1M的文件,若是代碼中有對文件進行操做的,如寫入,移動等,都php-fpm至少要再分配3倍的空間,如3M。若是是上傳10M的文件,則要30M php-fpm內存。

相關文章
相關標籤/搜索