Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7793391
  • 博文数量: 701
  • 博客积分: 2150
  • 博客等级: 上尉
  • 技术积分: 13233
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-29 16:28
个人简介

天行健,君子以自强不息!

文章分类

全部博文(701)

文章存档

2019年(2)

2018年(12)

2017年(76)

2016年(120)

2015年(178)

2014年(129)

2013年(123)

2012年(61)

分类: 架构设计与优化

2015-02-25 15:17:45

一. 相关模块安装
查看Nginx是否安装了这两个模块(nginx_upload_module和nginx_uploadprogress_module),
使用命令:
$ nginx -V (注意是大写),可以
查看Nginx当时编译时候的参数,如果发现有上述两个模块,说明Nginx已经安装了这两个模块。
如果没有的话,就需要安装这两个Nginx模块。


1. 下载nginx_upload_modul
下载链接:

$ wget
$ tar xvzf nginx_upload_module-2.2.0.tar.gz


2. 下载nginx_uploadprogress_module
网址:

下载链接:

$ unzip nginx-upload-progress-module-master.zip 


二、Nginx添加编译选项
由于这两个模块不在Nginx源代码中,需要重新编译Nginx,在编译选项中加上
--add-module=/模块源代码路径/nginx_upload_module-2.2.0 
--add-module=/模块源代码路径/nginx-upload-progress-module-maste 。 


$ make
$ make install


1. 编译时的错误提示
/opt/nginx_http_rtmp/nginx_upload_module-2.2.0/ngx_http_upload_module.c: In function 'ngx_http_read_upload_client_request_body':
/opt/nginx_http_rtmp/nginx_upload_module-2.2.0/ngx_http_upload_module.c:2628: error: 'ngx_http_request_body_t' has no member named 'to_write'
/opt/nginx_http_rtmp/nginx_upload_module-2.2.0/ngx_http_upload_module.c:2687: error: 'ngx_http_request_body_t' has no member named 'to_write'
/opt/nginx_http_rtmp/nginx_upload_module-2.2.0/ngx_http_upload_module.c: In function 'ngx_http_do_read_upload_client_request_body':
/opt/nginx_http_rtmp/nginx_upload_module-2.2.0/ngx_http_upload_module.c:2769: error: 'ngx_http_request_body_t' has no member named 'to_write'
/opt/nginx_http_rtmp/nginx_upload_module-2.2.0/ngx_http_upload_module.c:2785: error: 'ngx_http_request_body_t' has no member named 'to_write'
/opt/nginx_http_rtmp/nginx_upload_module-2.2.0/ngx_http_upload_module.c:2877: error: 'ngx_http_request_body_t' has no member named 'to_write'
make[1]: *** [objs/addon/nginx_upload_module-2.2.0/ngx_http_upload_module.o] Error 1
make[1]: Leaving directory `/opt/nginx_http_rtmp/nginx-1.6.0'
make: *** [build] Error 2
解决办法:




三、配置Nginx,实现上传模块来接收页面上传的文件。
把下面配置添加到Nginx的配置文件中,注意是加在server的上下文中。
        location = /upload {
                upload_pass     /service.php?path=uploadfile&a=upload_server;//表示Nginx接收完上传的文件后,然后交给后端处理的地址
                upload_cleanup 400 404 499 500-505; //表示当发生这些http status代码的情况下,会把上传的文件删除
                upload_store    /tmp/upload_tmp 1;//上传模块接收到的文件临时存放的路径, 1 表示方式,该方式是需要在/tmp/upload_tmp下创建以0到9为目录名称的目录,上传时候会进行一个散列处理。
                upload_store_access user:r; //指定访问模式
                upload_limit_rate 128k; //设定上传速度上限
                upload_set_form_field "${upload_field_name}_name" $upload_file_name; //设定后续脚本语言访问的变量,其中${upload_field_name}对照本例子就是addfile。比如后台PHP就可以通过$_POST['addfile_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_store设置了临时文件存放根路径,该路径就是经过散裂后上传文件存在真实路径,比如后续处理可以根据这值把上传文件拷贝或者移动到指定的目录下。
                upload_pass_form_field "^.*$";//
                upload_pass_args on;// 打开开关,意思就是把前端脚本请求的参数会传给后端的脚本语言,比如:脚本可以通过$_POST['k']来访问。
        }


上述配置完了,就可以实现上传的功能了。
但是,要获取上传的进度,那还是需要配置另外一个模块nginx_uploadprogress_module。
其实,获取当前进度原理比较简单,就是通过javascript以异步方式定时给特定地址发送请求,
这个模块会以json格式返回上传的进度。配置比较简单。
1)、首先打开这个模块功能,在Nginx配置文件中http上下文里面,增加upload_progress proxied 5m;
     其中,proxied表示名称(zone_name官方文档),5m表示每次链接存放跟踪信息的大小。
     另外,再设置返回格式为json,upload_progress_json_output;
2)、在上述的location = /upload中增加一个配置项track_uploads proxied 30s; 
     其中,proxied就是刚才在第一步设置的名字,30s表示每次链接处理完毕后,链接会保持30s。
3)、设置一个location来处理javascript发送请求。
location ^~ /progress {
  report_uploads proxied;    #GET此地址得到上传进度
}
4)、还有一个参数考虑设置upload_progress_header ,这个值缺省是X-Progress-ID。
有点类似SessionID,主要用在前台需要在上传文件的时候需要设置这个参数值,比如设置为uuid值。
这样javascript每次发送请求要获取上传进度时候,都需要带上这个参数,
这样上传进度跟踪模块才知道是返回那个链接的进度。
经过这三步骤,就把上传进度跟踪模块配置好了。

阅读(33866) | 评论(4) | 转发(0) |
给主人留下些什么吧!~~

gudeyang2015-04-17 11:27:36

bin376288755:编译时的错误提示,这个怎么解决啊???

http://blog.csdn.net/igame/article/details/17477351

回复 | 举报

gudeyang2015-04-17 11:27:27

dps迷失_:同问 编译时的错误怎么解决的呀

http://blog.csdn.net/igame/article/details/17477351

回复 | 举报

dps迷失_2015-04-02 17:26:06

同问 编译时的错误怎么解决的呀

bin3762887552015-03-27 14:53:15

编译时的错误提示,这个怎么解决啊???