중급 "업스트림을 읽는 동안 업스트림 연결이 조기에 종료되었습니다"

중급 "업스트림을 읽는 동안 업스트림 연결이 조기에 종료되었습니다"

내 서버에서 "업스트림을 읽는 동안 연결이 조기에 닫혔습니다."라는 중간 오류가 발생합니다. 이 오류는 Amazon S3에서 서버를 통해 요청된 데이터에서만 발생하며 서버 자체의 파일에서는 발생하지 않습니다.

내 설정은 다음과 같습니다.

Nginx nginx 버전: nginx/1.11.5(Ubuntu 저장소 외부)를 기반으로 하는 로드 밸런서 1개

구성은 다음과 같습니다.

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 구성(관련 부분 IMHO):

# 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이나 브라우저에서 로그에 있는 동일한 파일을 확인하면 문제 없이 이미지를 얻을 수 있습니다. 그러나 로그에는 문제가 있음이 표시됩니다.

관련 정보