在aws上的django频道:daphne和工作人员跑,但websocket taret不健康

问题描述 投票:0回答:2

我一直关注这篇文章 - https://blog.mangoforbreakfast.com/2017/02/13/django-channels-on-aws-elastic-beanstalk-using-an-alb/

让我的django-channels应用程序在aws上工作..但只有非websockets请求被处理。

我的频道图层设置是:

   CHANNEL_LAYERS = {
"default": {
    "BACKEND": "asgi_redis.RedisChannelLayer",
    "CONFIG": {
        "hosts": [os.environ.get('REDIS_URL', 'redis://localhost:6379')],
    },
    "ROUTING": "malang.routing.channel_routing",
 },
}

我在文章中提到了两个目标群体。一个转发路径/到端口80和/ ws / *到5000。

我的supervisord.conf是 -

[program:Daphne]
environment=PATH="/opt/python/run/venv/bin"
command=/opt/python/run/venv/bin/daphne -b 0.0.0.0 -p 5000 
malang.asgi:channel_layer
directory=/opt/python/current/app
autostart=true
autorestart=true
redirect_stderr=true
user=root
stdout_logfile=/tmp/daphne.out.log

[program:Worker]
environment=PATH="/opt/python/run/venv/bin"
command= /opt/python/run/venv/bin/python manage.py runworker
directory=/opt/python/current/app
process_name=%(program_name)s_%(process_num)02d
numprocs=4
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/tmp/workers.out.log

当我在aws日志上检查supervisorctl状态的结果时,它显示它们正常运行。但我仍然得到了404的回应。

如果您想了解更多信息,请帮助并告诉我们。

python django amazon-web-services django-channels daphne
2个回答
0
投票

该项目是否在本地运行?如果没有,问题出在软件上。如果是这样,问题在于您的部署。我会检查安全组/防火墙/ ELB配置,以确保可以访问正确的端口。


0
投票

在每个实例上本地运行Redis后端是没有意义的,前提是您实际部署了它,而您没有提供信息。 Redis是一个缓存系统,允许通过不同的实例共享数据。更接近于DB的架构观点,即一个简单的守护程序线程。您应该使用外部Redis缓存,并在Django conf上引用它。

CHANNEL_LAYERS = {
"default": {
    "BACKEND": "asgi_redis.RedisChannelLayer",
    "ROUTING": "<YOUR_APP>.routing.application",
    "CONFIG": {
        "hosts": ["redis://"+REDIS_URL+":6379"],
    },
},

}

请参阅AWS Elasticache服务。

© www.soinside.com 2019 - 2024. All rights reserved.