Nginx的Upload上傳模組
前段時間做一個專案,需要上傳檔案,差不多需要20M左右,普通用php處理會比較麻煩,經常超時,而且大量佔用資源。於是搜尋了下,決定用nginx的upload上傳模組來處理。
你可以在這裡:http://www.grid.net.ru/nginx/upload.en.html 獲取原始碼。下載以後需要重新編譯nginx
1
2
3
|
. /configure –add-module= /usr/local/nginx_upload_module- *
make make install
|
重啟nginx即可
以下是我的nginx配置檔案
前端頁面提交的時候直接提交到 http://test.local/upload 即可
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
server { listen 80;
server_name test . local ;
index index.php index.shtml index.htm index.html;
root /data/app/test . local /wwwroot ;
access_log off;
location /upload {
upload_pass /index .php?c=uploader&a=upload_server;
upload_cleanup 400 404 499 500-505;
upload_store /data/app/test . local /upload_tmp ;
upload_store_access user:r;
upload_limit_rate 128k;
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 "^.*$" ;
}
location ~ .*.php?$
{
include fastcgi_params;
}
location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 30d;
}
location ~ .*.(js|css)?$ {
expires 1d;
}
} |
大概解釋一下每個引數
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
upload_pass 指明瞭需要後續處理的php地址 upload_cleanup 如果php出現400 404 499 500-505之類的錯誤,則刪除上傳的檔案 upload_store 上傳檔案存放地址 upload_store_access 上傳檔案的訪問許可權,user:r是指使用者可讀 upload_limit_rate 上傳限速,如果設定為0則表示不限制 upload_set_form_field 設定額外的表單欄位。這裡有幾個可用的變數: $upload_file_name 檔案原始名字 $upload_field_name 表單的name值 $upload_content_type 檔案的型別 $upload_tmp_path 檔案上傳後的地址 upload_aggregate_form_field 額外的變數,在上傳成功後生成 $upload_file_md5 檔案的MD5校驗值 $upload_file_size 檔案大小 upload_pass_form_field 從表單原樣轉到後端的引數,可以正規表示式表示 官方的例子是upload_pass_form_field "^submit$|^description$" ;意思是把submit,description這兩個欄位也原樣通過upload_pass傳遞到後端php處理。如果希望把所有的表單欄位都傳給後端可以用upload_pass_form_field "^.*$" ;
|
相關文章
- nginx1.6 安裝上傳模組 nginx_upload_moduleNginx
- 封裝react antd的upload上傳元件封裝React元件
- 封裝Vue Element的upload上傳元件封裝Vue元件
- iView Upload 實現手動上傳View
- tinypng upload一鍵壓縮上傳工具
- Element-UI框架 —— Upload 上傳(圖片上傳格式和大小判斷)UI框架
- Element-UI框架 —— Upload 上傳(視訊上傳格式和大小判斷)UI框架
- layui的upload元件使用以及上傳阻止測試UI元件
- AntD框架的upload元件上傳圖片時使用customRequest方法自定義上傳行為框架元件
- elementui upload元件 上傳視訊到七牛雲UI元件
- Fusion Next 之 Upload 上傳元件設計思路元件
- vue使用ant design vue(upload)檔案上傳Vue
- 結合element-ui 的el-upload元件支援分片上傳UI元件
- nginx upload module安裝及使用Nginx
- 換個姿勢上傳?el-upload + qiniu-js 的實現JS
- vue3使用ElementPlus upload上傳檔案的兩種方式Vue
- CentOS下安裝Nginx並新增nginx_upload_moduleCentOSNginx
- React antdesign upload元件自定義上傳到S3React元件S3
- Vue +Element Ui 使用Upload元件實現多圖片上傳VueUI元件
- 上傳靶機實戰之upload-labs解題
- 上傳模組開發總結
- nginx upload 模組build錯誤解決error: variable ‘result’ set but not used [-Werror=unused-but-set-variable]NginxUIError
- Nginx常用的模組Nginx
- Nginx的Uwsgi模組Nginx
- elementUI中form表單的upload上傳圖片及校驗總結UIORM
- Nginx的Uwsgi模組(部分模組指令)Nginx
- 通用mapper、圖片上傳、nginxAPPNginx
- jquery.upload.js實現非同步上傳程式碼例項jQueryJS非同步
- jquery ajax file upload NET MVC 無重新整理檔案上傳jQueryMVC
- php 3個多檔案上傳(uploadify、file upload、 webuploader)PHPWeb
- 修改SharePoint上傳檔案大小限制(Changing Maximum Upload Size)
- Nginx 調整檔案上傳大小限制Nginx
- vue ElementUI upload上傳檔案時對檔案格式、大小和寬高的限制VueUI
- Alan`s blog — 檔案上傳模組
- NGINX模組(一)Nginx
- NGINX模組(二)Nginx
- Flask Web開發入門(十)之圖片上傳(使用Flask-Upload)FlaskWeb
- element-ui中上傳檔案uploadUI