我的简短问题是,如何在 AWS Elasticbeanstalk 上设置 Django-channels v2?下面是冗长且不那么吸引人的问题。 提前致谢!
我正在尝试使用 Django Channels 2.02 设置一个 elasticbeanstalk 实例。我跟着这个https://hackernoon.com/setting-up-django-channels-on-aws-elastic-beanstalk-716fd5a49c4a教程。为 channel 1 制作的教程。
Elasticbeanstalk 实例是使用应用程序负载均衡器 创建的。 Redis 4.0 实例正在运行 0.0.0.0:6379,由 netstat 确认。自定义 TCP,端口范围:6379,来源:redis 实例上的 0.0.0.0/0。
.ebekstension 中的 alb_listener.config:
option_settings: aws:elbv2:listener:80:
DefaultProcess: http
ListenerEnabled: 'true'
Protocol: HTTP aws:elasticbeanstalk:environment:process:http:
Port: '8000'
Protocol: HTTP
Daphne 服务器使用命令“Daphne .asgi:application”启动。监听 TCP 地址 0.0.0.0:8000。它返回:
2018-03-12 08:59:30,778 ERROR Exception inside application: [Errno -2] Name or service not known
File "/opt/python/run/venv/local/lib/python3.6/site-packages/channels/consumer.py", line 54, in __call__
await await_many_dispatch([receive, self.channel_receive], self.dispatch)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/channels/utils.py", line 47, in await_many_dispatch
result = task.result()
File "/opt/python/run/venv/local/lib/python3.6/site-packages/channels_redis/core.py", line 167, in receive
task.result()
File "/opt/python/run/venv/local/lib/python3.6/site-packages/channels_redis/core.py", line 187, in receive_loop
real_channel, message = await self.receive_single(general_channel)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/channels_redis/core.py", line 224, in receive_single
async with self.connection(index) as connection:
File "/opt/python/run/venv/local/lib/python3.6/site-packages/channels_redis/core.py", line 403, in __aenter__
self.conn = await aioredis.create_redis(**self.kwargs)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/aioredis/commands/__init__.py", line 174, in create_redis
loop=loop)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/aioredis/connection.py", line 107, in create_connection
timeout, loop=loop)
File "/usr/lib64/python3.6/asyncio/tasks.py", line 339, in wait_for
return (yield from fut)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/aioredis/stream.py", line 19, in open_connection
lambda: protocol, host, port, **kwds)
File "/usr/lib64/python3.6/asyncio/base_events.py", line 733, in create_connection
infos = f1.result()
File "/usr/lib64/python3.6/concurrent/futures/thread.py", line 55, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/lib64/python3.6/socket.py", line 743, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
[Errno -2] Name or service not known
Websocket 在浏览器控制台中没有返回错误。
它适用于我的本地运行服务器设置。问题是什么?你能帮我写一个配置脚本,这样我就不需要手动启动 Daphne 了吗?
最佳答案
这里的回复很晚。
问题出在教程中的 config:hosts
URL 上。从 URL 中删除 redis:// 部分。
例如,
REDIS_PUBLIC_DNS = "YOUR-REDIS-DNS.amazonaws.com"
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [(REDIS_PUBLIC_DNS, 6379)],
}
}
}
您可以使用 redis-cli 检查连接,
redis-cli -h REDIS-PUBLIC-DNS-url ping ;you should expect PONG in response.
关于amazon-web-services - Django channel 2 和 EC2/Elasticbeanstalk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49231599/