AWS EC2 Behind ELB Always Prints Error Unexpected response code: 400
See original GitHub issueHey guys -
Can’t seem to find out a solution for this, but when I run my app behind a load balancer, I get this error on the client:
WebSocket connection to 'wss://fakedomain.com/socket.io/?EIO=3&transport=websocket&sid=QH8VmXbiEcp3ZyiLAAAD' failed: Error during WebSocket handshake: Unexpected response code: 400
I understand the error, since it’s trying to talk to the load balancer and now the EC2 instance (I’m not great with AWS so feel free to offer help on this one!) but what I don’t understand is how to make the error not show up!
I’d love to fix the root cause but I’m guessing it involves a separate dedicated socket.io server to handle all the real time stuff which I don’t have time for at the moment, but could someone please run me through supressing this error?
I’m assuming it’s falling back to polling, which seems to work just fine (I have the socket connection connected and it fires) but I don’t want to launch with a red error in my console.
Thanks in advance for any advice you might have!
Issue Analytics
- State:
- Created 9 years ago
- Comments:67
Top GitHub Comments
I assume you’re not using Elastic Beanstalk (the instructions there would be much easier).
Go to EC2->Network & Security->Load Balancers
Select your load balancer and go to Listeners. Ensure that both the Load Balancer protocol and the Instance Protocol are set to TCP for port 80 and SSL for port 443 rather than HTTP and HTTPS.
I found that on Elastic Beanstalk even though i had setup the Load balancer to use TCP and SSL with the web interface, when I checked the load balancer config directly it was still using HTTPS for the secure listener. So you should probably check in the EC2 > Load Balancers section that the ports are setup as they should be:
Once that is sorted add the following to .ebextensions and all works well for me 😃
This will only work 100% when you only have one instance however, because sticky session support doesnt work over TCP.