Nginx upstream timed out (110: Connection timed out) while connecting to upstream

I have Nginx & App running in container (Kubernetes). Using NginX entry point for TLS handshaking with following configuration

    upstream app {
        server app:8200;
    }

    server {
        listen                  443 ssl;
        server_name             localhost;
        ssl_certificate         /etc/ssl/util_example_com.crt;
        ssl_certificate_key     /etc/ssl/util_example_com.key;
        ssl_client_certificate  /etc/ssl/ca.crt;
        ssl_protocols           TLSv1.2 TLSv1.3;
        ssl_ciphers             HIGH:!aNULL:!MD5;
        ssl_verify_client       on;

        location / {
                proxy_pass         http://app;
                proxy_read_timeout 180;
                proxy_set_header   X-Forwarded-For $remote_addr;
                proxy_http_version 1.1;
                proxy_set_header   Upgrade $http_upgrade;
                proxy_set_header   Connection 'upgrade';
                proxy_set_header   Host $host;
                proxy_cache_bypass $http_upgrade;
        }

    }

I can curl http://app:8080/generator from Nginx Container. But when I do the same on Public endpoint with curl (https://util.example.com/generator) which hits Nginx first, I get 504 Gateway Time-out & following error in Nginx

2021/05/04 21:54:50 [error] 21#21: *1 upstream timed out (110: Connection timed out) while connecting to upstream, client: 10.2.16.183, server: localhost, request: "POST /generator HTTP/1.1", upstream: "http://172.20.154.113:8200/generator", host: "util.example.com"

any help on, whats going on here.


Solution 1:

Try removing all non-essential parts. E.g. try the below minimum working example: (edit the sub.domain.tld)

upstream app {
        server app:8200;
    }

    server {
        listen                  443 ssl;
        server_name             sub.domain.tld;
        ssl_certificate         /etc/ssl/util_example_com.crt;
        ssl_certificate_key     /etc/ssl/util_example_com.key;
        location / {
                proxy_pass         http://app;
        }
    }

From there add elements until you find what causes the timeout.