title: Websocket Wss on on AWS Application Load Balancer or Network Load Balancer
body: <p>I have spent hours trying to come up with a solution and read a lot of web socket solution with a nginx, still no luck</p>
  
  <p>I have a websocket application containerised with docker and running on ec2 instances using ecs. my websocket need to be able to autoscale when needed. </p>
  
  <p>I have tested connectivity with Classic elb and all works well but it doesn't support websocket protocol. </p>
  
  <p>Down to ALB and NLB </p>
  
  <p>ALB only allows HTTP and HTTPS protocol and support websockets and i am unsure of how to implement that to achieve accessing my websocket over the WSS protocol also target group heath checks fails.</p>
  
  <p>NLB works well as it allows TCP protocol but the only issue is that it doesn't terminate SSL. </p>
  
  <p>The only solution was to install the SSL cert on the EC2 and setup nginx reverse proxy to the docker container. but i have had no joys with that as i have had no experience with Nginx i might not have the right config. but i am still not able to connect to websocket over wss. Any assistance welcomed</p>
  
  <p>My main objective is connecting to websocket over wss.</p>
  
  <pre><code>worker_processes 1;
  
  events { worker_connections 1024; }
  
  http {
  
  sendfile on;
  
  upstream docker-nginx {
      server nginx:443;
      ssl_certificate /etc/ssl/private/example.chained.crt;
      ssl_certificate_key /etc/ssl/private/example.key;
      ssl_session_timeout 1d;
      ssl_session_cache shared:SSL:50m;
      ssl_session_tickets off;
  }
  
  upstream localhost {
      server apache:443;
  }
  
  server {
      listen 443;
  
      location / {
          proxy_pass         http://localhost;
          proxy_redirect     off;
          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 {
      listen 443;
  
      location / {
          proxy_pass         http://example.com;
          proxy_redirect     off;
          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;
      }
    }
  
  }
  </code></pre>