基于Nginx实现文件上传
需要安装一个nginx-upload-module
下载地址:https://github.com/vkholodkov/nginx-upload-module/tree/2.255
不要使用master,会报错,缺少一个 md5.h
如下便是nginx的配置文件写的很详细了
location /upload
{
default_type application/json;
if ($request_method ~* "OPTIONS") {
return 200 '{"code": -1,"msg": "正在处理中..."}';
}
upload_pass /file/upload/deal; #文件上传完成后nginx将转发如下参数到后台处理
upload_resumable on; #断点续传
upload_store /tmp/upload_tmp; #文件保存地址
upload_limit_rate 500k; #上传限速 0 表示不限速
upload_store_access user:rw; #临时文件权限
upload_set_form_field "${upload_field_name}_name" $upload_file_name; #表单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; #文件md5
upload_aggregate_form_field "${upload_field_name}_size" $upload_file_size; #文件大小
#upload_pass_form_field "^submit$|^description$";
upload_pass_form_field "^.*$"; #表单参数
upload_pass_args on; #转发参数
upload_cleanup 400 404 499 500-505; #如果出现这些错误将删除保存的文件
}
如果想要查看上传进度,需要安装nginx-upload-progress-module