
Я получаю промежуточные ошибки "upstream earlierly closed connection while reading upstream" на моем сервере. Ошибка возникает только в данных, которые запрашиваются сервером из 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;
}
- 2 фронт-сервера с Nginx. Конфигурация у них абсолютно одинаковая, и я покажу здесь только частичную конфигурацию, полная слишком большая.
Конфигурация 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, если я указываю from из load balancer на Front-серверы, ошибки нет. Если я проверяю тот же файл, который находится в журнале в Curl или браузере, я получаю изображение без проблем. Но журналы показывают, что есть проблема.