Websockets with AWS and Elastic Beanstalk

元气小坏坏 提交于 2019-12-04 08:10:59

问题


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.

  1. Go to EB environment page
  2. Configuration
  3. 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

  1. In the AWS console, open the EC2 tab.
  2. Select the relevant region and click on Security Group.
  3. You should have an elasticbeanstalk-default security group if you have launched an Elastic Beanstalk instance in that region for your app.
  4. click on Actions button at top, and select Edit inbound rules.
  5. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!