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

nginx带进度条的上传超大文件

阅读更多
11年写的
http://haoningabc.iteye.com/blog/1711534
重新整理下
准备----------------------------------------------

nginx-1.8.1.tar.gz 能过,
  1.10不行,会有openssl md5之类的错误

上传
https://github.com/vkholodkov/nginx-upload-module/tree/2.2
nginx-upload-module-2.2.zip 

上传进度条
https://www.nginx.com/resources/wiki/modules/upload_progress/
使用v0.8.4 的版本
masterzen-nginx-upload-progress-module-v0.8.4-0-g82b35fc.tar.gz

上传进度条客户端:
https://github.com/drogus/jquery-upload-progress



跑php的fcgi
spawn-fcgi-1.6.3.tar.bz2


yum install openssl-devel zlib-devel prce-devel -y
这些 nginx需要用到的

yum install php php-devel -y

安装-----------------------------------------

安装spawn-fcgi
tar xvf spawn-fcgi-1.6.3.tar.bz2
./configure --prefix=/usr/local/spawn
make
make install


启动脚本
runcgi.sh

#
!/bin/sh
export PHP_FCGI_MAX_REQUESTS=0
/usr/local/spawn/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u haoning -g haoning -f /usr/bin/php-cgi -P /var/run/fastcgi-php.pid



安装nginx
编译nginx
./configure --prefix=/usr/local/nginx  --add-module=/opt/masterzen-nginx-upload-progress-module-82b35fc --add-module=/opt/nginx-upload-module-2.2 
make
make install


nginx配置文件
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.139.114;  
        charset utf-8,gb2312;  
        client_max_body_size 12000m;  
        location /upload {  
                upload_pass   @test;  
                #upload_store /tmp 1; 
		upload_store /tmp;   
                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:9000;  
            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;   
    }  
  
}


客户端
jquery-upload-progress-master.zip
解压到
/usr/local/nginx/html/
cd  /usr/local/nginx/html/jquery-upload-progress-master/example
vim index.html
<body>
          <form id="upload" enctype="multipart/form-data" action="index.html" method="post">
        <input name="file" type="file"/>
        <input type="submit" value="Upload"/>
      </form>

改成
<body>
          <form id="upload" enctype="multipart/form-data" action="/upload" method="post">
        <input name="file" type="file"/>
        <input type="submit" value="Upload"/>
      </form>

因为nginx配置的/upload

加一个请求返回的php返回值
test.php
<?php  
print_r($_POST);  
?> 




启动
export PHP_FCGI_MAX_REQUESTS=0
/usr/local/spawn/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u haoning -g haoning -f /usr/bin/php-cgi -P /var/run/fastcgi-php.pid

/usr/local/nginx/sbin/nginx



cd /tmp
watch -n 1  'ls -lh'
查看上传的文件

chmod -R 777 /tmp

浏览器访问
http://192.168.139.122/jquery-upload-progress-master/example/



效果













  • 大小: 5.1 KB
分享到:
评论

相关推荐

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

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

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

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

    nginx_uploadprogress_module-0.9.0

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

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

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

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

    1. 文件无任何依赖可以编译成linux,window,arm平台都能使用 2. 单文件根据执行参数可以既可以当服务端用也可以当...10. 命令行窗口带进度条显示 11. 基于websocket协议非常容易用nginx反向代理容易实现7层负载均衡

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

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

    KODExplorer 芒果云-资源管理器

    [关于上传问题] 程序没有做任何限制,如果需要上传大文件,则修改 php.ini:`upload_max_filesize = 1000M post_max_size = 1000M` [关于解压缩问题] 程序不做任何限制,如若失败请设置php内存限制。memory_limit ...

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

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

    单点登录源码

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

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

    01 selctors实现文件上传与下载 02 html的介绍 03 html文档树的概念 04 meta标签以及一些基本标签 05 img标签和列表标签 06 form表单之input标签 07 通过form向server端发送数据 08 form表单之select标签 09 table...

Global site tag (gtag.js) - Google Analytics