阅读背景:

使用Django在AWS上使用EC2对Websockets进行故障排除

来源:互联网 

I am using Django-Channels to try to get real time features such as chat/messaging, notifications, etc. Right now, I have gotten everything to work fine on my laptop using the settings described in the docs here: https://channels.readthedocs.io/en/latest/. I use a local redis server for testing purposes.

我正在使用Django-Channels来尝试获取实时功能,例如聊天/消息,通知等。现在,我已经使用此处文档中描述的设置在我的笔记本电脑上正常工作:http:// channels .readthedocs.io / EN /最新/。我使用本地redis服务器进行测试。

However, when I deploy to my Amazon EC2 Elastic Beanstalk server (using an AWS ElastiCache Redis), the WebSocket functionality fails. I was reading and I think it is due to the fact that Amazon's HTTPS does not support WebSockets, so I need to switch to Secure TCP. I tried doing that with: https://blog.jverkamp.com/2015/07/20/configuring-websockets-behind-an-aws-elb/ and https://medium.com/@Philmod/load-balancing-websockets-on-ec2-1da94584a5e9#.ak2jh5h0q but to no avail.

但是,当我部署到我的Amazon EC2 Elastic Beanstalk服务器(使用AWS ElastiCache Redis)时,WebSocket功能失败。我正在阅读,我认为这是因为亚马逊的HTTPS不支持WebSockets,所以我需要切换到安全TCP。我试过这样做:https://blog.jverkamp.com/2015/07/20/configuring-websockets-behind-an-aws-elb/和https://medium.com/@Philmod/load-balancing- websockets-on-ec2-1da94584a5e9#.ak2jh5h0q但无济于事。

Does anyone have any success implementing WebSockets with CentOS/Apache and Django on AWS EB? The Django-Channels package is fairly new so I was wondernig if anyone has experienced and/or overcome this hurdle. Thanks in advance

有没有人在AWS EB上使用CentOS / Apache和Django实现WebSockets有什么成功? Django-Channels包是相当新的,所以如果有人经历过和/或克服了这个障碍,我就会受到影响。提前致谢

4 个解决方案

#1


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.

AWS推出了支持Web套接字的新Application Load Balancer。将您的ELB更改为应用程序负载均衡器,这将解决您的问题。

https://aws.amazon.com/blogs/aws/new-aws-application-load-balancer/

https://aws.amazon.com/blogs/aws/new-aws-application-load-balancer/

#2


2  

As described here it's possible to run Django Channels on Elastic Beanstalk using an Application Load Balancer.

如此处所述,可以使用应用程序负载均衡器在Elastic Beanstalk上运行Django Channels。

In a simplified form, it's basically:

在简化形式中,它基本上是:

  1. Create an ALB
  2. 创建一个ALB
  3. Add 2 target groups, one that points to port 80, and one that points to Daphne port, ie 8080.
  4. 添加2个目标组,一个指向端口80,另一个指向达芙妮端口,即8080。
  5. Create 2 path rules. Let the default route point to target group 1 (port 80), and set the second to use a relative path, ie. /ws/ and point it to target group 2.
  6. 创建2个路径规则。让默认路由指向目标组1(端口80),并将第二个路由指向使用相对路径,即。 / ws /并将其指向目标组2。
  7. Add Daphne and workers to supervisord (or another init system)
  8. 将Daphne和工人添加到supervisord(或其他init系统)
  9. DONE! Access Daphne/websockets through the relative url ws://example.com/ws/.
  10. DONE!通过相对URL ws://example.com/ws/访问Daphne / websockets。

#3


1  

I suppose that is late, but I found this article https://blog.mangoforbreakfast.com/2017/02/13/django-channels-on-aws-elastic-beanstalk-using-an-alb/

我想这已经晚了,但我发现这篇文章https://blog.mangoforbreakfast.com/2017/02/13/django-channels-on-aws-elastic-beanstalk-using-an-alb/

#4


0  

I suppose ALB is the only way. The reason is because with the SSL protocol listner in the classic LB, the session stickiness and X-Forwaded headers won't be forwarded and will result in the proxy server redirect loop. Doc is here,

我想ALB是唯一的方法。原因是因为使用经典LB中的SSL协议列表器,会话粘性和X-Forwaded标头将不会被转发,并将导致代理服务器重定向循环。 Doc在这里,

https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-listener-config.html

https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-listener-config.html

I'll update the answer if I find out a way with the existing CLB.

如果我找到现有CLB的方法,我会更新答案。


分享到: