nginx文件上传模块+Tonado

做文件上传的项目,需要上传文件,使用Nginx的upload上传模块来进行处理。

源码位置:http://www.grid.net.ru/nginx/upload.en.html

下载后重新编译nginx

 

./configure –add-module=/usr/local/nginx_upload_module-*

 

make

 

make install

nginx配置如下:

        location /video/ {
            upload_pass @after_upload;
            upload_store /data0/video_temp;
            #upload_store_access user:rw;

            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_form_field "^.*(?!Filedata)$";
  
            #upload_pass_form_field "^.*$";      
            
            error_page 405 =200 @after_upload;
    
            #upload_cleanup 400 404 499 500-505;


        }

        location @after_upload {
            proxy_pass http://videoupload_backend;
        }
upload_pass 指明了需要后续处理的函数调用方法
 
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 "^.*$";

 

上传完成后 该请求直接upstream到后台的web frame后台处理。

这里使用的是Tornado,主要是做一些数据信息存储和返回给前端的事情,代码很简单 就不贴了。

总的来说 使用nginx+torando还是很方便的,tornado作为异步非阻塞的python web框架,用起来挺舒服的。

 

 

 

posted on 2013-01-29 17:31  浪迹天涯cc  阅读(797)  评论(0编辑  收藏  举报

导航