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

谁说我不能喝 提交于 2019-11-29 22:39:25

Nginx+php-fpm架构,遇到这个错误时:Request Entity Too Large 或 Nginx 413 Request Entity Too Large,需要做如下调整即可。

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

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

超时设置:
 

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

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

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

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

;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 = 3M

 

3、修改配置三:优化php-fpm配置

php_admin_value[memory_limit] = 1224M

3/28 UPDATE:假设上传1M的文件,如果代码中有对文件进行操作的,如写入,移动等,都php-fpm至少要再分配3倍的空间,如3M。如果是上传10M的文件,则要30M php-fpm内存。

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!