0

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

如果您需要更多信息,请帮助并告诉我。

4

2 回答 2

0

在每个实例上本地运行 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 服务。

于 2018-08-24T16:56:56.360 回答
0

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

于 2017-06-25T18:19:57.330 回答