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

原创
2018/06/11 19:29
阅读数 517
AI总结

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内存。

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
2 收藏
0
分享
AI总结
返回顶部
顶部