`
haoningabc
  • 浏览: 1446438 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

nginx 上传进度条

阅读更多
费劲周折,一晚上终于搞定了,nginx版本1.38
--------------

---------------
测试php是否好使
cat index.php
<?php  phpinfo(); ?> 

nginx上传进度条
4部分
1.php的支持,自带的,就是建立一个fast-cgi跑php,提供一个test.php显示最终结果
2.nginx_upload_module 上传插件
http://www.grid.net.ru/nginx/download/nginx_upload_module-2.2.0.tar.gz
3.nginx_upload_progress_module,上传进度条插件
akostrikov-nginx-upload-progress-module-v0.8.2-1-g3d8e105.zip
http://wiki.nginx.org/HttpUploadProgressModule
下载
https://nodeload.github.com/akostrikov/nginx-upload-progress-module/zipball/master
4.https://github.com/drogus/jquery-upload-progress ,显示进度条的jquery插件


参考链接:
http://wiki.nginx.org/HttpUploadProgressModule
http://www.grid.net.ru/nginx/upload.en.html

nginx基础的包:
yum install openssl-devel zlib-devel prce-devel
./configure --prefix=/usr/local/nginx --add-module=/usr/local/app/nginx_upload_module-2.2.0 --add-module=/usr/local/app/masterzen-nginx-upload-progress-module-a788dea --with-debug


如果
/usr/local/app/nginx_upload_module-2.2.0/ngx_http_upload_module.c: 在函数‘ngx_http_upload_merge_ranges’中:
/usr/local/app/nginx_upload_module-2.2.0/ngx_http_upload_module.c:1682:22: 错误:变量‘result’被设定但未被使用 [-Werror=unused-but-set-variable]

出现这个错误
就把Makefile文件里的 -Werror去掉
在fedora17中遇到
在redhat6.3中没有




配置文件需要注意
注意,官方的配置文件不对
需要加个这个
location ~ (.*)/x-progress-id:(\w*) {
			rewrite ^(.*)/x-progress-id:(\w*)   $1?X-Progress-ID=$2;
		}


php的支持:
yum install spawn-fcgi
yum install php
yum install php-cgi
test.php
[root@haoning html]# cat test.php 
<?php
print_r($_POST);
?>

启动fast-cgi支持php
groupadd www-data
useradd www-data -g www-data
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9001 -u www-data -g www-data -f /usr/bin/php-cgi -P /var/run/fastcgi-php.pid


配置文件问:
nginx.conf
[root@fedora17 conf]# cat nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
	autoindex on; 
	autoindex_exact_size off; 
	autoindex_localtime on; 
	default_type application/octet-stream; 
	sendfile on; 
	tcp_nopush on;
	tcp_nodelay on;
	keepalive_timeout 10;
	gzip on;
	gzip_min_length 1k;
	gzip_buffers 4 8k;
	gzip_http_version 1.1;
	gzip_comp_level 3;
	gzip_types text/css text/xml text/plain application/x-javascript application/xml application/pdf application/rtf application/x-perl application/x-tcl application/msword application/vnd.ms-excel application/vnd.ms-powerpoint application/vnd.wap.xhtml+xml image/x-ms-bmp;
	gzip_vary on;
	output_buffers 4 32k;
	upload_progress_json_output;
	upload_progress proxied 1m;
	server {
		listen       80;
		server_name  192.168.76.138;
		charset utf-8,gb2312;
		client_max_body_size 2000m;
		location /upload {
				upload_pass   @test;
				upload_store /tmp 1;
				upload_store_access user:r;
				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 "^submit$|^description$";
				track_uploads proxied 30s;
		}   
		location @test {
				rewrite	^(.*)$	/test.php last;
		}   

		location / {
            proxy_set_header Host $http_host;
			root   html;
			index  index.html index.htm index.php;
		}

 		location ~ (.*)/x-progress-id:(\w*) {
            rewrite ^(.*)/x-progress-id:(\w*)   $1?X-Progress-ID=$2;
        }
		location ^~ /progress {
            report_uploads proxied;
        }
		location ~ \.php$ { 
			fastcgi_pass 127.0.0.1:9001;
			fastcgi_index index.php;
			set $path_info "/";
			set $real_script_name $fastcgi_script_name;
			if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") { set $real_script_name $1;
				set $path_info $2;
			} 
		} 
		location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { 
			root html;
			access_log off;
			expires 30d;
		} 
		location ~ .*\.(js|css|ico)?$ { 
			root html;
			access_log off;
			expires 1h;
		} 
		error_page 500 502 503 504 /50x.html;
		location = /50x.html { 
			root html;
		} 
		fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
		fastcgi_param script_name $real_script_name;
		fastcgi_param path_info $path_info;
		include /usr/local/nginx/conf/fastcgi_params; 
	}

}



简单例子测试是否可以上传
<html>
<head>
<title>Test upload</title>
</head>
<body>
<h2>Select files to upload</h2>
<form enctype="multipart/form-data" action="/upload" method="post">
<input type="file" name="file1"><br>
<input type="file" name="file2"><br>
<input type="file" name="file3"><br>
<input type="file" name="file4"><br>
<input type="file" name="file5"><br>
<input type="file" name="file6"><br>
<input type="submit" name="submit" value="Upload">
<input type="hidden" name="test" value="value">
</form>
</body>
</html>

注意/tmp权限
mkdir /tmp/1 2 3 ...
chmod -R 777 /tmp

然后用jquery的插件的版本:

[root@haoning example]# cat index.html 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<title>ajaxFileUpload</title>
	    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<script src="../lib/jquery.js"></script>
		<script src="../jquery.uploadProgress.js"></script>
		<script type="text/javascript">
			$(function() {
				$('form').uploadProgress({
					/* scripts locations for safari */
					jqueryPath: "../lib/jquery.js",
					uploadProgressPath: "../jquery.uploadProgress.js",
					start:function(){},
					uploading: function(upload) {$('#percents').html(upload.percents+'%');},
					interval: 2000
			    });
			});
		</script>
		<style type="text/css">
			.bar {
			  width: 300px;
			}
			
			#progress {
			  background: #eee;
			  border: 1px solid #222;
			  margin-top: 20px;
			}
			#progressbar {
			  width: 0px;
			  height: 24px;
			  background: #333;
			}
		</style>
	</head>
	
	<body>  
	  <form id="upload" enctype="multipart/form-data" action="/upload" method="post"><!--注意这里改了-->
        <input name="file" type="file"/>
        <input type="submit" value="Upload"/>
      </form>
		
	    <div id="uploading">
	      <div id="progress" class="bar">
	        <div id="progressbar">&nbsp;</div>
	      </div>
	    </div>
		<div id="percents"></div>
	</body>
</html>


附件中有下好的安装包,不保函yum的
  • 大小: 12.1 KB
分享到:
评论

相关推荐

    nginx TOMCAT 文件下载 上传 进度条 缓存

    NULL 博文链接:https://yhq1212.iteye.com/blog/2235726

    nginx_uploadprogress_module-0.9.0

    nginx的文件上传获取实时进度条模块

    uploadify3与struts2结合实现有进度条文件上传实例

    3) 修改服务器端可上传文件大小的限制 在文件 usr local nginx conf nginx conf中修改client max body size 毕竟是第一次用 不是很熟悉 希望有人发现问题可以交流一下"&gt;这是根据uploadify3 2结合struts2搭建的...

    Nginx上传文件全部缓存解决方案

    下面通过文字说明给大家详解Nginx上传文件全部缓存解决方案。 因为应用服务器(Jetty)里面实现了上传时写了进度条。经过缓存。就没法读取到进度了。此外,在Nginx处缓存文件,也降低了传输效率。 nginx采用1.5.6。 ...

    基于mangos的websocket协议跨平台文件传输工具

    1. 文件无任何依赖可以编译成linux,window,arm平台都能使用 2. 单文件根据执行参数可以既可以当服务端用也可以当客户端用 3. 支持上传模式和下载...11. 基于websocket协议非常容易用nginx反向代理容易实现7层负载均衡

    xchan:xchan 是一个对象存储工具,对接七牛云,供个人开发者使用

    p 8089切换端口,且切换后自行用 Nginx 反向代理的形式配置直接访问即可进入安装引导界面六、注意事项当你使用第三方上传时(七牛云),后台界面上传成功的进度条不代表真实的上传进度。例如:当你上传大文件时,也许你...

    单点登录源码

    各个子系统前台thymeleaf模板,前端资源模块,使用nginx代理,实现动静分离。 &gt; zheng-upms 本系统是基于RBAC授权和基于用户授权的细粒度权限控制通用平台,并提供单点登录、会话管理和日志管理。接入的系统可自由...

    chibisafe:节点中编写的快速文件上传器和超棒的掩体! :rocket:

    根据您拥有多少文件可能要花费几分钟或几小时,有一个进度条可以使您有所了解。这是什么? Chibisafe是一种用node编写的文件上传器服务,旨在易于使用和设置。 它主要用于图像和视频,但是可以接受您扔给它的任何...

    KODExplorer 芒果云-资源管理器

    - 全平台兼容性:Win Linux Mac (Apache、Nginx、IIS) #### 2.使用场景: - 取代FTP,服务端、客户端软件等复杂的安装配置。kod可以一键安装随处使用. - 你可以用它来管理你的服务器(备份,在线解压缩,版本发布......

    python入门到高级全栈工程师培训 第3期 附课件代码

    08 FTP之进度条 09 FTP之cd切换 11 FTP之创建文件夹及MD5校验思路 第33章 01 操作系统历史 02 进程的概念 03 线程的概念 04 线程的调用以及join方法 05 setDaemon方法和继承式调用.baiduyun.downloading 05 ...

Global site tag (gtag.js) - Google Analytics