'How do I diagnose a long Initial Connection to webpage hosted in AWS with Nginx/ELB/ECS

I have a React web page that uses the Razzle framework for SSR, containerised and deployed into ECS along with an Nginx container. I use Route 53 for DNS, which routes the record to an ELB, then to the target group where my container resides.

If I clear all browsing data and go to the site, it takes over a minute to establish an "Initial Connection" and everything else looks quick. Subsequent loads of the page do not take long at all.

Timing panel from Chrome Dev Tools

I have no idea where to start to diagnose the issue, does anyone have an idea where I should look?

Here is my Nginx configuration file

server {
  listen 80;
  listen [::]:80;

  if ($http_x_forwarded_proto = 'http'){
    return 301 https://$host$request_uri;
  }

  location / {
    proxy_pass http://0.0.0.0:3000;
    proxy_http_version 1.1;
    proxy_redirect     off;
    proxy_set_header   Upgrade $http_upgrade;
    proxy_set_header   Connection "Upgrade";
    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   X-Forwarded-Host $server_name;
  }
}

server {
  server_name www.<domain>.com;
  return 301 $scheme://<domain>.com$request_uri;
}


Solution 1:[1]

I found my issues was due to my ELB configuration where I had two private subnets associated instead of public subnets. After creating a public subnet in each availability zone and associating it with the ELB the initial connection time became negligible.

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 Ed Whittle