中間「上流の読み取り中に上流の接続が途中で閉じられました」

中間「上流の読み取り中に上流の接続が途中で閉じられました」

サーバー上で「アップストリームの読み取り中にアップストリームの接続が途中で閉じられました」という中間エラーが発生しています。このエラーは、Amazon S3 からサーバー経由で要求されたデータに対してのみ発生し、サーバー自体のファイルに対しては発生しません。

私の設定は次のとおりです:

1 Nginx ベースのロードバランサー nginx バージョン: nginx/1.11.5 (Ubuntu リポジトリ外)

構成は次のとおりです。

server {

    server_name  example.com

    client_body_timeout 12s;
    client_header_timeout 12s;
    keepalive_timeout 15s;

    access_log off;
    proxy_connect_timeout 1000s;
    proxy_send_timeout 1000s;
    proxy_read_timeout 1000s;
    send_timeout 1000s;

    location / {
            set $ua $http_user_agent;

            if ($http_user_agent = "")
            {
                    set           $ua "Fixing-Empty-User-Agent";
            }


            proxy_pass http://front_least;
            proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
            proxy_redirect off;
            proxy_buffering off;
            proxy_ignore_client_abort on;
            proxy_set_header    Host            $host;
            proxy_set_header    X-Real-IP       $remote_addr;
            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header    Accept-Encoding "";
    }
}

    upstream front_least {
    least_conn;
    server localF1.example.com;
    server localF2.example.com;
    server f1.example.com backup; # Public ports
    server f2.example.com backup; # Public ports
    keepalive 32;
}
  1. Nginx がインストールされている 2 つのフロント サーバー。これらの間の構成はまったく同じですが、完全な構成は大きすぎるため、ここでは部分的な構成のみを示します。

F 構成 (私見では関連部分):

# Fix S3 Content Type error
    map $uri $custom_content_type {
            default "binary/octet-stream";
            ~(.*\.png)$ "image/png";
            ~(.*\.jpg)$ "image/jpeg";
            ~(.*\.jpeg)$ "image/jpeg";
            ~(.*\.gif)$ "image/gif";
            ~(.*\.ico)$ "image/x-icon";
    }

server {
    listen       80;
    server_name  example.com *.example.com;
    ssl_prefer_server_ciphers on;
    ssl_protocols SSLv3 TLSv1;

    gzip on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";
    gzip_proxied any;
    gzip_buffers 16 8k;
    gzip_types text/plain text/css application/javascript text/xml application/xml+rss;
    gzip_vary on;

    pagespeed on;

    ...
    Huje amount of lines related to pagespeed
    ...

   location /gallery/ {
        try_files $uri @s3icons;
    }
    location /gallery_thumbnails/ {
        try_files $uri @s3icons;
    }
    location /icon/ {
        try_files $uri @s3icons;
    }
    location /screenshot/ {
        try_files $uri @s3icons;
    }
    location /vendor/ {
        try_files $uri @s3icons;
    }

    location @s3icons {

            proxy_set_header       Host 'bucket_name.s3.amazonaws.com';
            proxy_set_header       Authorization '';
            proxy_hide_header      x-amz-id-2;
            proxy_hide_header      x-amz-request-id;
            proxy_hide_header      Set-Cookie;
            proxy_ignore_headers   "Set-Cookie";
            proxy_intercept_errors on;
            proxy_hide_header Content-Type;
            add_header Content-Type $custom_content_type;

            proxy_http_version     1.1;
            proxy_set_header       Connection "";
            proxy_pass http://s3_icons;

    }

    include common/error.conf;
    include common/deny.conf;
}


    # Define a mapping used to mark HTML as uncacheable.
      map $upstream_http_content_type $new_cache_control_header_val {
        default $upstream_http_cache_control;
        "~*text/html" "no-cache, max-age=0";
      }

upstream s3_images {
    server bucket_1.s3.amazonaws.com;
    keepalive 10;
}

upstream s3_icons {
    server bucket_2.s3.amazonaws.com;
    keepalive 10;
}

現在、S3 からの画像でのみエラーが発生しています。ロード バランサーからフロント サーバーにポイントすると、エラーは発生しません。ログにある同じファイルを Curl またはブラウザーで確認すると、問題なく画像を取得できます。ただし、ログには問題があることが示されています。

関連情報