Nginx的Upload上传模块

 

nginx-upload-prgress下载地址:http://wiki.nginx.org/NginxHttpUploadProgressModule
nginx-upload-module下载地址及相关说明:http://www.grid.net.ru/nginx/upload.en.html


接下来安装Nginx
1.安装Nginx所需的pcre库:
# unzip pcre-8.21.zip 
# ./configure 
# make && make install

2.安装Nginx
# groupadd www
# useradd -g www www
# unzip masterzen-nginx-upload-progress-module-v0.8.2-0-g8b55a34.zip 
# unzip nginx_upload_module-2.2.0.zip 
# tar xvf nginx-1.0.11.tar.gz 
# cd nginx-1.0.11
# ./configure --prefix=/usr/local/webserver/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --add-module=../masterzen-nginx-upload-progress-module-8b55a34/ --add-module=../nginx_upload_module-2.2.0
# make && make install


配置Nginx如下,部分如下
server
    {
    listen       80;
    server_name web.test.com;
        index index.html index.htm;
        root /data/html/www;
        if ($host = 'test.com' )
        {

                rewrite ^/(.*)$ http://web.test.com/$1 permanent;  
       
        }
        if (-d $request_filename)
       
        {
   
                rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
   
        }

    # Upload form should be submitted to this location
    location /upload {
          # Set specified fields in request body
            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;

          # Inform backend about hash and size of a file
            upload_aggregate_form_field "${upload_field_name}_md5" $upload_file_md5;
            upload_aggregate_form_field "${upload_field_name}_size" $upload_file_size;

            upload_pass /test ;
            upload_pass_args on;
            upload_limit_rate 128k;
            upload_store /data/html/www/source/image/sourceImage;
   
            upload_store_access user:r;
 
            upload_pass_form_field "^.*$";
            upload_cleanup 400 404 499 500-505;
            }

        
    location /test {
        proxy_pass   http://localhost:10000/image/upload;
        }


       # Pass altered request body to a backend
        location ~ .*\.php {
              #fastcgi_pass  unix:/tmp/php-cgi.sock;
              fastcgi_pass  127.0.0.1:9000;
              fastcgi_index index.php;
              include fcgi.conf;
            }
    }


大概解释一下每个参数 
upload_pass 指明了需要后续处理的地址
upload_cleanup 如果出现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传递到后端处理。如果希望把所有的表单字段都传给后端可以用upload_pass_form_field "^.*$";

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值