问题
I'm trying to get my websockets working with Amazon Web Service and Elastic Beanstalk (ELB).
I set up a proxy protocol according to: http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/enable-proxy-protocol.html
I've opened up all inbound traffic to my load balancer and other security groups on all ports, for all IPs.
I also kept the load balancer listerner as HTTP on port 80.
My websocket connection gives the following error when trying to connect on port 80: failed: Error during WebSocket handshake: Unexpected response code: 400
And this error on port 8080: failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
Would appreciate suggestions, I'm stuck at this point.
Thanks!
回答1:
After configuring EC2 Security group your application will work with public IP.
But you still will get issue with using EB URL. To solve this issue, you have to change EB configuration.
- Go to EB environment page
- Configuration
- In Load Balancing section change protocol from HTTP to TCP.
Now you can click EB URL.
回答2:
AWS has launched new Application Load Balancer that supports web sockets. Change your ELB to Application Load Balancer and that will fix your issue.
https://aws.amazon.com/blogs/aws/new-aws-application-load-balancer/
回答3:
You should create reverse proxy for Nginx server. You can include this config file in you .ebextensions folder to make Nginx support WS.
Also in the EBS's load balancer configuration change the protocol from HTTP to TCP.
Refer this blog to set up secure WebSocket.
回答4:
I was also looking for possible workaround for this issue, but it's quite easy irrespective of what platform language you are using to develop websocket program on AWS EC2, as am using Node.js nginx in my case, this should work for all supporting platforms.
Configure Security Group
- In the AWS console, open the EC2 tab.
- Select the relevant region and click on Security Group.
- You should have an elasticbeanstalk-default security group if you have launched an Elastic Beanstalk instance in that region for your app.
- click on Actions button at top, and select Edit inbound rules.
- here in Type column select All TCP, or you can set some Custom TCP
rule as well to listen at your websocket port.
And that's it!
Note: If something is not working, check the "Events" tab in the Beanstalk application / environments and find out what went wrong.
来源:https://stackoverflow.com/questions/27436110/websockets-with-aws-and-elastic-beanstalk