负载均衡器后面的 Nginx 反向代理几个小时后停止工作

负载均衡器后面的 Nginx 反向代理几个小时后停止工作

在我的 Rancher 环境中,我使用内置的入口负载均衡器将流量路由到自定义 nginx,它充当 2 个“应用程序”的反向代理。在条件中,我选择要代理的服务器。一切正常,但在随机时间之后应用程序不可用。在浏览器中我收到 504 和基本 nginx 消息,An error occurred. blah blah Faithfully yours, nginx.我使用来自 dockerhub 的 nginx:lts

nginx

2021/02/25 19:46:27 [error] 31#31: *789 upstream timed out (110: Connection timed out) while connecting to upstream, client: X.X.X.X, server: _, request: "GET / HTTP/1.1", upstream: "http://10.42.0.36:8080/", host: "www.example.com"
2021/02/25 19:47:27 [info] 31#31: *789 client X.X.X.X closed keepalive connection

如果我重新启动 nginx 容器,一切都会在几个小时内再次正常运行。

配置

worker_processes                    auto;
error_log                           /dev/stdout info;
pid                                 /run/nginx.pid;

include                             /usr/share/nginx/modules/*.conf;

events {
    worker_connections              1024;
    multi_accept                    on;
}

http {
    log_format                      main    '$remote_addr - $remote_user [$time_local] "$request" '
                                            '$status $body_bytes_sent "$http_referer" '
                                            '"$http_user_agent" "$http_x_forwarded_for"';

    access_log                      /dev/stdout;

    client_body_buffer_size         10K;
    client_header_buffer_size       1k;
    client_max_body_size            100m;
    large_client_header_buffers     4 32k;
    server_names_hash_bucket_size   64;
    sendfile                        on;
    tcp_nodelay                     on;
    tcp_nopush                      on;
    keepalive_requests              1000;
    reset_timedout_connection       on;
    client_body_timeout             10;
    send_timeout                    5;
    server_tokens                   off;
    keepalive_timeout               65;
    types_hash_max_size             2048;

    include                         /etc/nginx/mime.types;
    default_type                    application/octet-stream;

    server {
        listen                      8080 default_server;
        server_name                 _;

        charset                     utf-8;
        underscores_in_headers      on;

        root                        /usr/share/nginx/html;

        location / {
            proxy_http_version      1.1;
            proxy_read_timeout      120;
            proxy_cache_bypass      true;
            proxy_no_cache          true;
            proxy_connect_timeout   20s;

            if ($http_user_agent ~ someagent) {
                proxy_pass              http://app1:8000;
            }
        
            proxy_pass              http://app2:8080;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
}

相关内容