nginx带进度条的上传超大文件
程序员文章站
2022-07-01 16:04:06
...
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
启动脚本
runcgi.sh
安装nginx
编译nginx
nginx配置文件
客户端
jquery-upload-progress-master.zip
解压到
/usr/local/nginx/html/
cd /usr/local/nginx/html/jquery-upload-progress-master/example
vim index.html
改成
因为nginx配置的/upload
加一个请求返回的php返回值
test.php
启动
cd /tmp
watch -n 1 'ls -lh'
查看上传的文件
chmod -R 777 /tmp
浏览器访问
http://192.168.139.122/jquery-upload-progress-master/example/
效果
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/
效果