基于Nginx實(shí)現(xiàn)文件上傳

基于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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容