首页 > 解决方案 > 上游在发送到客户端时过早关闭连接

问题描述

当我尝试从我的服务器下载文件时遇到问题。当我通过快速互联网连接下载文件时,一切都很好..但其他互联网速度慢的用户无法完成下载。下载文件在 7 分钟后中止并出现错误:

[error] 194621#194621: *135815 upstream  prematurely closed connection while sending to client...

我的服务器配置(基于 docker)

前端nginx:

   location / {
            proxy_pass http://172.26.141.15;
            proxy_http_version 1.1;
            proxy_buffering off;
            proxy_redirect off;
            proxy_request_buffering off;
            proxy_connect_timeout 7200s;
            proxy_send_timeout 7200s;
            proxy_read_timeout 7200s;
            proxy_buffer_size 64k;
            proxy_buffers 16 32k;
            proxy_busy_buffers_size 64k;
            proxy_temp_file_write_size 64k;

            proxy_set_header Host $host;
            proxy_set_header REMOTE_ADDR $remote_addr;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header If-Range "";

后端 nginx

upstream ui_loadbalancer {
        ip_hash;
        server filehost-php:9000; # location of my first php-fpm server
    }

  server {
    listen 80;
    client_body_in_file_only clean;
    client_body_buffer_size 32K;
    client_max_body_size 80M;

    keepalive_timeout 15;

    sendfile on;
    sendfile_max_chunk 512k;
    send_timeout 10;


    location / {
        try_files $uri /index.php$is_args$args;
     }

    location ~ ^/index\.php(/|$) {
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        fastcgi_pass ui_loadbalancer;
        include fastcgi_params;
       fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
       fastcgi_param DOCUMENT_ROOT $realpath_root;
       internal;
    }

另外我已经扩展了 php.ini

"max_execution_time = 7200"

和 php-fpm

"request_terminate_timeout = 7200"

你有什么想法为什么下载在大约 7 分钟后中止?

标签: nginxdownloadconnection

解决方案


推荐阅读