nginx上传进度结合正常请求

nginx上传进度结合正常请求

我有一个很好的 nginx 虚拟主机,无需使用 nginx 上传模块就能很好地运行。 当我将上传进度添加到我的上传请求中时。我该如何解决这个问题?我需要使用/?r=upload或上传我的文件并使用或其他方式/upload?foo=bar跟踪上传进度数据。/progress

# static9-localhost.sweb
server {

        # upload limit
        # upload_limit_rate 10240;

        # request size limitation
        client_max_body_size 500m;
        client_body_buffer_size 64k;

        # document root
        root /path/to/webapp/static/public/;

        # index file
        index index.php;

        # server name
        server_name static9-localhost.sweb;

        # rewrite rules
        rewrite "^/thumbnail/([A-Za-z0-9]{12})/(.*)/.*$" /index.php?r=thb&unique=$1&prm=$2 last;

        # /
        location @frontcontroller {
                # expires
                expires max;

                # disable etag
                if_modified_since off;
                add_header 'Last-Modified' '';

                # mvc rewrite
                try_files $uri $uri/ /index.php?$uri&$args;
        }

        # upload progress
        location /upload {
                upload_pass @frontcontroller;
                track_uploads proxied 600s;
        }

        # progress
        location = /progress {
                report_uploads proxied;
        }

        # error pages
        error_page 404 /index.php?r=404;
        error_page 403 /index.php?r=403;
        error_page 500 501 502 503 504 /index.php?r=500;

        # php5-fpm
        location ~ \.php$ {
                fastcgi_pass 127.0.0.1:9003;
                fastcgi_index index.php;
                fastcgi_read_timeout 300;
                include fastcgi_params;
        }

        # logs
        access_log /path/to/webapp/logs/static_access.log;
        error_log /path/to/webapp/logs/static_error.log;
} 

对于上述虚拟主机,我的上传请求/upload/?X-Progress-ID=QLiFKnG5A81K冻结了。问题是什么?

/?r=blahblah如果我将上传的文件发送出去/upload使用,我也需要这样的请求才能正常工作/?r=upload

答案1

我查看了我的配置以找到一个可行的示例。我使用上传模块和上传进度的方式如下:

    upload_progress proxied 4m;
    ...
    server {
        ...

        location ^~ /progress {
                report_uploads proxied;
        }

        location ^~ /services/ {
               rewrite ^/(.*?)/?$ /$1.php break;
               fastcgi_pass unix:/var/run/php5-fpm.sock;
               include fastcgi_params;
        }

        location ^~ /upd/ {
               upload_pass   /services/upload/;
               upload_pass_args on;
               upload_store_access group:rw;
               upload_store /tmp;

               set $upload_field_name file;
               upload_set_form_field $upload_field_name.name "$upload_file_name";
               upload_set_form_field $upload_field_name.path "$upload_tmp_path";
               upload_aggregate_form_field "$upload_field_name.size" "$upload_file_size";
               upload_cleanup 400 404 499 500-505;
               track_uploads proxied 30s;
       }
  }

还要查看 firebug Net 选项卡。查看您的代码是否获得正确的 json 输出。也许问题实际上出在客户端。

相关内容