0

In my environment in rancher I use built in ingress load balancer to route trafic to custom nginx, which acts like reverse proxy for 2 "apps". In condition i choose which server I want to proxy. Everything works fine, but after random time application is not available. In browser i get 504 and basic nginx message An error occurred. blah blah Faithfully yours, nginx. I use nginx:lts from dockerhub

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

If I restart nginx container, everything works again for a few hours.

config

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 {
        }
    }
}
l2ysho
  • 101
  • 2
  • Nginx is fine, you need to examine why the upstream stops working, or is answering slowly, longer than proxy_read_timeout configured for nginx. – drookie Mar 02 '21 at 14:18
  • @drookie I proxy to another nginx servises, when it goes down I just restart this nginx and everything works. Also when it goes down both services not working. If I bypass this nginx and setup ingress to services everything working, there is no issue with slow response i think – l2ysho Mar 02 '21 at 16:08

0 Answers0