【问题标题】:django channels on aws : daphne and workers running but websocket taret unhealthyaws 上的 django 频道:daphne 和工作人员正在运行,但 websocket taret 不健康
【发布时间】:2017-11-28 15:57:09
【问题描述】:

我一直在关注这篇文章-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 状态的结果时,它显示它们运行良好。但我仍然得到 ws 的 404 响应。

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

【问题讨论】:

  • 我正在尝试同样的事情,使用应用程序负载均衡器。你能帮帮我吗?

标签: python django amazon-web-services django-channels daphne


【解决方案1】:

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

【讨论】:

  • 它在本地运行得非常好。一个问题..redis端口"hosts": [os.environ.get('REDIS_URL', 'redis://localhost:6379')],应该和daphne的端口一样吗?因为到目前为止我在 5000 上运行 daphne,而 redis 被定义为在 6379 上运行。
  • @PradeepSaini 我对达芙妮一无所知,所以我无法告诉你如何配置它。
【解决方案2】:

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

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

}

请参阅 AWS ElasticCache 服务。

【讨论】:

    猜你喜欢
    • 2016-09-17
    • 2021-08-21
    • 2018-03-21
    • 2021-08-21
    • 2020-01-08
    • 1970-01-01
    • 2017-10-12
    • 1970-01-01
    • 2023-01-08
    相关资源
    最近更新 更多