使用 nginx_upload_module上传大附件
由于PHP会上传超时,不能限速!
php.ini中的配置对nginx_upload_module没有影响。
如果要上传大文件,可以在nginx.conf中的http部分添加一行:
client_max_body_size 50m;
另外还要进行上传的配置:
location = /suibian-shezhi.htm {
upload_pass @utest;
upload_store /tmp/nginx_upload;
upload_store_access user:rw;
upload_set_form_field "${upload_field_name}_name" $upload_file_name;
upload_set_form_field "${upload_field_name}_content_type" $upload_content_type;
upload_set_form_field "${upload_field_name}_path" $upload_tmp_path;
upload_aggregate_form_field "${upload_field_name}_md5" $upload_file_md5;
upload_aggregate_form_field "${upload_field_name}_size" $upload_file_size;
upload_pass_form_field "^.*$";
#upload_limit_rate 1000k; (用于限速)
upload_cleanup 400 404 499 500-505;
}
location @utest{
rewrite ^(.*)$ /index.php last;
}
如何安装:
之前已安装nginx但没有装这个module
重新安装过。
1.下载nginx wget http://nginx.org/download/nginx-1.3.0.tar.gz
2, 下载nginx upload module模块
wget http://www.grid.net.ru/nginx/download/nginx_upload_module-2.2.0.tar.gz
3. 解压缩nginx_upload_module 这个解压就可以了,不需要安装什么的
4. ./configure --prefix=.... --add-module=../nginx_upload_module-2.2.0/
注意要添加--add-module 可以是相对路径,也可以是绝对路径
相关配置:
注意:需要修改php.ini以下参数
file_uploads on 是否允许通过http上传
upload_max_filesize 8m 允许上传文件的最大大小
post_max_size 8m 通过表单POST给php所能接收的最大值
另外nginx.conf中设置上传文件大小
upload_max_file_size 软限制
client_max_body_size 硬限制