基于Nginx實(shí)現(xiàn)文件上傳
需要安裝一個(gè)nginx-upload-module
下載地址:https://github.com/vkholodkov/nginx-upload-module/tree/2.255
不要使用master芒粹,會(huì)報(bào)錯(cuò),缺少一個(gè) md5.h
如下便是nginx的配置文件寫(xiě)的很詳細(xì)了
location /upload
{
default_type application/json;
if ($request_method ~* "OPTIONS") {
return 200 '{"code": -1,"msg": "正在處理中..."}';
}
upload_pass /file/upload/deal; #文件上傳完成后nginx將轉(zhuǎn)發(fā)如下參數(shù)到后臺(tái)處理
upload_resumable on; #斷點(diǎn)續(xù)傳
upload_store /tmp/upload_tmp; #文件保存地址
upload_limit_rate 500k; #上傳限速 0 表示不限速
upload_store_access user:rw; #臨時(shí)文件權(quán)限
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; #文件上傳后保存在服務(wù)器上的地址
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 "^.*$"; #表單參數(shù)
upload_pass_args on; #轉(zhuǎn)發(fā)參數(shù)
upload_cleanup 400 404 499 500-505; #如果出現(xiàn)這些錯(cuò)誤將刪除保存的文件
}
如果想要查看上傳進(jìn)度油航,需要安裝nginx-upload-progress-module