我这样设置我的 nginx 静态内容域:
# static0.mywebsite.com static1.mywebsite.com static2.mywebsite.com static3.mywebsite.com
server {
# upload limit
# upload_limit_rate 10240;
# request size limitation
client_max_body_size 500m;
client_body_buffer_size 64k;
# document root
root /home/mywebsite/myns-projects/mywebsite_com/static/public/;
# index file
index index.php;
# server name
server_name static0.mywebsite.com;
# rewrite rules
rewrite "^/thumbnail/([A-Za-z0-9]{12})/(.*)/.*$" /index.php?request=thumbnail&unique=$1¶meters=$2 last;
# set myns no cache
set $myns_no_cache 1;
if ($request_uri ~* "/thumbnail\/.*/") {
set $myns_no_cache 0;
}
if ($request_uri ~* "/serve\/.*\.(jpg|gif|png|swf)/") {
set $myns_no_cache 0;
}
if ($request_uri ~* "/serve\/.*\.(jpg|gif|png|swf)/") {
set $myns_no_cache 0;
}
# upload
location /upload {
# proxy to upstream server
proxy_pass http://static0.mywebsite.com;
proxy_redirect default;
# track uploads
track_uploads uploadproxied 10s;
# mvc rewrite
try_files $uri $uri/ /index.php?request=upload&$args;
}
# /
location / {
# expires
expires max;
# disable etag
if_modified_since off;
add_header 'Last-Modified' '';
# mvc rewrite
try_files $uri $uri/ /index.php?$uri&$args;
}
# progress
location /progress {
# report uploads tracked in the 'proxied' zone
report_uploads uploadproxied;
}
# php5-fpm
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9003;
fastcgi_param myns_PATH /home/mywebsite/myns;
fastcgi_index index.php;
fastcgi_read_timeout 300;
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_cache_bypass $myns_no_cache;
fastcgi_no_cache $myns_no_cache;
fastcgi_cache mynsCACHE;
fastcgi_cache_valid any 1h;
}
# deny access to .htaccess and .user.ini files
location ~ /\.[ht|user] {
deny all;
}
# disable access log for better performace use at will
# access_log /home/mywebsite/myns-projects/mywebsite_com/logs/static_access.log;
access_log off;
# logs
error_log /home/mywebsite/myns-projects/mywebsite_com/logs/static_error.log;
}
提交响应后,jsonp 返回良好但始终received
相等size
。
jQuery110109778769564112372_1428954161844({ "state" : "uploading", "received" : 2461040, "size" : 2461040 });
Nginx 版本:
:~# nginx -V
nginx version: nginx/1.6.2
built by gcc 4.7.2 (Debian 4.7.2-5)
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt=-Wl,-z,relro --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-file-aio --with-http_spdy_module --with-http_addition_module --with-http_dav_module --with-http_flv_module --with-http_geoip_module --with-http_gzip_static_module --with-http_gunzip_module --with-http_image_filter_module --with-http_mp4_module --with-http_perl_module --with-http_random_index_module --with-http_secure_link_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module --add-module=/usr/src/nginx/source/dotdeb-nginx/debian/modules/headers-more-nginx-module --add-module=/usr/src/nginx/source/dotdeb-nginx/debian/modules/naxsi/naxsi_src --add-module=/usr/src/nginx/source/dotdeb-nginx/debian/modules/nginx-auth-ldap --add-module=/usr/src/nginx/source/dotdeb-nginx/debian/modules/nginx-auth-pam --add-module=/usr/src/nginx/source/dotdeb-nginx/debian/modules/nginx-cache-purge --add-module=/usr/src/nginx/source/dotdeb-nginx/debian/modules/nginx-dav-ext-module --add-module=/usr/src/nginx/source/dotdeb-nginx/debian/modules/nginx-development-kit --add-module=/usr/src/nginx/source/dotdeb-nginx/debian/modules/nginx-echo --add-module=/usr/src/nginx/source/dotdeb-nginx/debian/modules/ngx-fancyindex --add-module=/usr/src/nginx/source/dotdeb-nginx/debian/modules/nginx-push-stream-module --add-module=/usr/src/nginx/source/dotdeb-nginx/debian/modules/nginx-lua --add-module=/usr/src/nginx/source/dotdeb-nginx/debian/modules/nginx-upload-progress --add-module=/usr/src/nginx/source/dotdeb-nginx/debian/modules/nginx-upstream-fair --add-module=/usr/src/nginx/source/dotdeb-nginx/debian/modules/nginx-syslog --add-module=/usr/src/nginx/source/dotdeb-nginx/debian/modules/ngx_http_pinba_module --add-module=/usr/src/nginx/source/dotdeb-nginx/debian/modules/ngx_http_substitutions_filter_module --add-module=/usr/src/nginx/source/dotdeb-nginx/debian/modules/ngx_pagespeed --add-module=/usr/src/nginx/source/dotdeb-nginx/debian/modules/nginx-x-rid-header --add-module=/usr/src/nginx/source/dotdeb-nginx/debian/modules/nginx-rtmp-module --with-ld-opt=-lossp-uuid
答案1
我遇到了这个问题,并创建了一个拉取请求,以使用 HTTP/2 恢复 nginx-upload-progress 模块的功能
https://github.com/masterzen/nginx-upload-progress-module/pull/57
修复此问题后,它就能像以前一样正常工作了。
答案2
track_uploads 语法:track_uploads <区域名称> <超时>
默认:不适用
语境: 地点
此指令启用对当前位置的上传跟踪。此位置的每个 POST 请求都将在 zone_name 上传进度跟踪器中注册请求。由于 Nginx 尚不支持 RFC 1867 上传,因此位置必须是 proxy_pass 或 fastcgi 位置。POST 必须具有一个名为 X-Progress-ID 的查询参数(或同名的 HTTP 标头),其值是用于获取进度信息的唯一标识符。如果 POST 没有此类信息,则不会跟踪上传。跟踪的连接在完成后最多保留 timeout 秒,以便能够为上传进度探测器提供无用信息。警告:此指令必须是位置的最后一个指令。它必须位于 proxy_pass 或 fastcgi_pass 位置。在某个位置重复此指令将导致段错误。
因此,看来 track_uploads 必须是 location 块中的最后一个指令。尝试在 location 中切换track_uploads
和try_files
指令/upload
。
答案3
我无法评论先前的答案
我有同样的问题
location ^~ /upload/progress {
upload_progress_json_output;
report_uploads uploadtracker;
}
location / {
uwsgi_pass core;
uwsgi_param HTTP_X_FORWARDED_PROTO $scheme;
include /etc/nginx/uwsgi_params;
uwsgi_read_timeout 300;
uwsgi_send_timeout 300;
track_uploads uploadtracker 300s;
}
但仍然立即收到等于大小
JavaScript的
$.ajax({
type: "GET", //post gives 405
url: "/upload/progress/",
beforeSend: function(request) {
request.setRequestHeader("X-Progress-ID", uuid);
request.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
},
success: function(response) {
try {
switch(response.state) {
case "uploading":
percent = parseInt(Math.floor((response.received / response.size)*100)); // always 100
PS:我发现 http2 破坏了它,如果没有 http2,监听一切正常:https://github.com/masterzen/nginx-upload-progress-module/issues/45