'Nginx: upstream server temporarily disabled while proxying connection

I am running Nginx on ECS Fargate with below config to implement a passthrough TLS proxy. I am getting intermittent errors - upstream server temporarily disabled while proxying connection in some of the AWS regions. The backend domain is an API Gateway domain.

stream {
  map_hash_max_size 256;
  map_hash_bucket_size 256;

  map $ssl_preread_protocol $tlsmap {
      "TLSv1.2"                $upstream;
      "TLSv1.3"                $upstream;
      default                  blackhole;
  }

  map $ssl_preread_server_name $upstream {
        <api_domain> api_domain;
        default blackhole;
  }

  upstream api_domain {
        server api_domain:443;
  }

  upstream blackhole {
        server  127.0.0.1:123;
  }

  server {
        listen 443;
        proxy_pass $tlsmap;
        ssl_preread on;
  }
}

Below is the nginx log for the request:

{
    "time_local": "<removed>",
    "remote_addr": "<removed>",
    "remote_port": "24907",
    "ssl_preread_server_name": "<removed>",
    "ssl_preread_protocol": "TLSv1.2",
    "status": "200",
    "bytes_sent": "0",
    "bytes_received": "0",
    "session_time": "60.012",
    "upstream_addr": "<removed>",
    "upstream_bytes_sent": "0, 517",
    "upstream_bytes_received": "0, 0",
    "upstream_connect_time": "-, 0.000",
    "connection": "85860",
    "ssl_protocol": "",
    "ssl_cipher": ""
}

Any pointers on what configuration can be fine tuned to fix this ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source