I have a node.js websocket server running on an EC2 instance on port 8080. Normal websocket connections (ws://
) work fine but when I'm trying to make a secure connection (wss://
), the websocket connection fails.
I realise that wss requests are sent to port 443, so I'm using ALB to forward requests on port 443 to port 8080. Since I'm very new to AWS I don't know if I'm doing this properly. Here's what I have done.
- Node.js server listening on port 8080 in an EC2 instance.
- These are the inbound security rules to that EC2 instance
- An application load balancer with listener
HTTPS: 443
It forwards it to my EC2 instance on port 8080 using HTTPS protocol. I have also attached an SSL certificate to the ALB.
I just cannot figure out what I'm doing wrong. Any help is appreciated.
UPDATE:
- I have created two security groups (ec2-sg and alb-sg) and configured them such that ec2-sg receives traffic from alb-sg.
Inbound security rules (alb-sg)
Outbound security rule (alb-sg)
Inbound security rules (ec2-sg)
However, I cannot get it to work. The target group passes the health check, I have enabled sticky session but the websocket connection keeps failing. The normal ws connection which used to work has also stopped working. This leads me to believe that I'm messing something up with the ALB (since it is working without the load balancer)
Update 2:
I enabled access logs for my load balancer. Here's the log:
https 2021-10-08T08:55:39.157549Z app/alb-latest/3e73469ba9514449 167.94.138.60:32854 172.31.93.226:8080 -1 -1 -1 502 - 41 1215
"GET https://3.208.76.74:443/ HTTP/1.1" "-" ECDHE-RSA-AES128-GCM-SHA256 TLSv1.2 arn:aws:elasticloadbalancing:us-east-1:144045735746:targetgroup/ec2-8080-server/2cbf4f7eb51c201e
"Root=1-6160078b-606aed86364c5e3f7db627f1" "-" "arn:aws:acm:us-east-1:144045735746:certificate/53a04011-1ea7-4689-b6c6-a7372e42191d" 0 2021-10-08T08:55:39.156000Z
"forward" "-" "-" "172.31.93.226:8080" "-" "-" "-"
ALB Listeners I have also enabled group-level stickiness on the target group for 1 day