AWS Application Load Balancer上的Websocket + SSL

MaxBlax360

我在ElastickBeanstalk上部署了Django应用程序。为了支持Websocket(由Django-channels(〜= 1.1.8,channels-api == 0.4.0组成),Redis Elasticache AWS和Daphne(〜= 1.4))。HTTP,HTTPS和Web套接字协议运行正常。

但是我找不到在安全SSL上部署Websocket的方法。它杀了我,并且正在阻止,因为来自浏览器的HTTPS连接将切断不安全的ws://对等请求。

这是我的ALB配置有人可以作为解决方案吗?

在此处输入图片说明

MaxBlax360

经过2天的调查,我终于破解了此配置!

答案是:

  1. The right, and MINIMUM, aws - ALB Config: 在此处输入图片说明 Indeed, we need to

    • Decode SSL ( this is not a End-to-End encryption )
    • Forward All traffic to Daphne. The reason why I did not go for the very spread among the web conf : "/ws/*" routing to Daphne, is that It provided me indeed the HandShake OK, but afterward, nothing, nada, websocket could not be pushed back to the subscriber. The reason, I believe, is that the push back from Daphne does not respect the custom base trailing URL you customize in your conf. Also, I cannot be sure of this interpretation. What I am sure of however is that if I don't forward all traffic to Daphne, it doesn't work after handshake.

      1. The minimum Deployment CONF
    • NO NEED of complet .ebextension override proxy in deployment:

在此处输入图片说明 .ebextensions/05_channels.config

files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/start_supervisor.sh":
  mode: "000755"
  owner: root
  group: root
  content: |
    #!/usr/bin/env bash
    sudo virtualenv -p /usr/bin/python2.7 /tmp/senv
    source /tmp/senv/bin/activate && source /opt/python/current/env
    sudo python --version > /tmp/version_check.txt
    sudo pip install supervisor

    sudo /usr/local/bin/supervisord -c /opt/python/current/app/fxf/custom_eb_deployment/supervisord.conf
    sudo /usr/local/bin/supervisorctl -c /opt/python/current/app/fxf/custom_eb_deployment/supervisord.conf reread
    sudo /usr/local/bin/supervisorctl -c /opt/python/current/app/fxf/custom_eb_deployment/supervisord.conf update
    sudo /usr/local/bin/supervisorctl -c /opt/python/current/app/fxf/custom_eb_deployment/supervisord.conf restart all
    sudo /usr/local/bin/supervisorctl -c /opt/python/current/app/fxf/custom_eb_deployment/supervisord.conf status
  • start_daphne.sh(根据我的ALB conf,备注我选择的是8001端口)

    #!/usr/bin/env bash source /opt/python/run/venv/bin/activate && source /opt/python/current/env /opt/python/run/venv/bin/daphne -b 0.0.0.0 -p 8001 fxf.asgi:channel_layer

  • start_worker.sh

    #!/usr/bin/env bash source /opt/python/run/venv/bin/activate && source /opt/python/current/env python /opt/python/current/app/fxf/manage.py runworker

  • 主管

`

[unix_http_server]
file=/tmp/supervisor.sock   ; (the path to the socket file)

[supervisord]
logfile=/tmp/supervisord.log ; supervisord log file
loglevel=error ; info, debug, warn, trace
logfile_maxbytes=50MB        ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10           ; (num of main logfile rotation backups;default 10)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false               ; (start in foreground if true;default false)
minfds=1024                  ; (min. avail startup file descriptors;default 1024)
minprocs=200                 ; (min. avail process descriptors;default 200)

; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket

[program:Daphne]
environment=PATH="/opt/python/run/venv/bin"
command=sh /opt/python/current/app/fxf/custom_eb_deployment/start_daphne.sh --log-file /tmp/start_daphne.log
directory=/opt/python/current/app
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/tmp/daphne.out.log
stderr_logfile=/tmp/daphne.err.log

[program:Worker]
environment=PATH="/opt/python/run/venv/bin"
command=sh /opt/python/current/app/fxf/custom_eb_deployment/start_worker.sh --log-file /tmp/start_worker.log
directory=/opt/python/current/app
process_name=%(program_name)s_%(process_num)02d
numprocs=2
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/tmp/workers.out.log
stderr_logfile=/tmp/workers.err.log

; When resorting to send SIGKILL to the program to terminate it
; send SIGKILL to its whole process group instead,
; taking care of its children as well.
killasgroup=true

`

如果有些人仍在为此会议上挣扎,我可能会在中等或类似的东西上发布一个tuto。请毫不犹豫地在答案上逼我;)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用AWS Application Load Balancer的Websocket超时

在AWS Application Load Balancer上使用Go时,WebSocket连接失败并显示301

在Elastic Beanstalk前面的Application Load Balancer上终止SSL

AWS Application Load Balancer是否实际上支持压缩?

AWS Elastic Load Balancer的SSL证书配置错误

将SSL证书上传到AWS Elastic Load Balancer

AWS Elastic Load Balancer有选择地启用SSL

我是否需要在AWS上的Load Balancer后面的所有Web服务器上安装ssl证书?

服务器上的AWS Load Balancer,静态IP和SSL终端(不是负载均衡器)

何时在AWS中通过API网关使用Application Load Balancer?

使用Ansible创建AWS Application Load Balancer规则

AWS Application Load Balancer无法连接到Tableau Service Manager

AWS Application Load Balancer 真实用户ip问题

AWS Application Load Balancer运行状况检查失败

我的 AWS Application Load Balancer 如何获得比请求更多的 503?

诊断AWS Application Load Balancer的响应时间慢

结合使用AWS ECS Service发现和Application Load Balancer

如何将域名连接到 AWS Application Load Balancer?

无法通过AWS Elastic Load Balancer进行与MySQL容器的SSL加密连接

使用AWS Load Balancer时出现ERR_SSL_PROTOCOL_ERROR

如何在AWS Load Balancer URL上使用https协议?

在us-east-1之外,如何结合使用AWS API Gateway和HTTPS的Application Load Balancer?

AWS Application Load Balancer无法通过Apache / MySQL DB处理登录表单请求

除非允许所有流量,否则无法访问 Aws Application Load Balancer

代理协议可以与AWS Application Load Balancer一起使用吗?

AWS CloudFormation:Application Load Balancer的目标组不适用于多个EC2实例

如何在AWS Application Load Balancer中限制文件上传大小?

将静态IP地址分配给AWS Application Load Balancer

如何在AWS Application Load Balancer(ALB)端口转发中转发端口