Nginx中nginx_upload_module上傳模組安裝配置

來源:互聯網
上載者:User

安裝nginx_upload_module模組

 

 代碼如下 複製代碼
./configure –add-module=/usr/local/nginx_upload_module-*
make
make install

重啟nginx即可

以下是我的nginx設定檔

前端頁面提交的時候直接提交到 http://dev.local/upload 即可

 代碼如下 複製代碼


server
{
listen 80;
server_name test.local;
index index.php index.shtml index.htm index.html;
root  /data/app/dev.local/wwwroot;
access_log  off;
 
location /upload {
upload_pass     /upload;
upload_cleanup 400 404 499 500-505;
upload_store    /data/app/dev.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;
}
 
}

參數注釋:

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 從表單原樣轉到後端的參數,可以Regex表示
官方的例子是upload_pass_form_field "^submit$|^description$";意思是把submit,description這兩個欄位也原樣通過upload_pass傳遞到後端php處理。如果希望把所有的表單欄位都傳給後端可以用upload_pass_form_field "^.*$";

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.