【发布时间】:2019-08-19 13:14:43
【问题描述】:
我正在尝试使用 django-channels 部署 django 应用程序。当我在开发环境中运行服务器时,它运行良好。但是在部署时,websocket 崩溃并出现错误 500。
我在 linux debian stretch 9.9 VPS 上使用 django 2.2.2、channels 2.2.0 和 asgiref 3.1.4、python 3.6(我自己编译,因为在 stretch 上不可用)和 nginx 引擎。
我关注https://djangodeployment.readthedocs.io/en/latest/01-getting-started.html 上的部署教程以及我尝试调整页面https://channels.readthedocs.io/en/latest/deploying.html 但主要是https://avilpage.com/2018/05/deploying-scaling-django-channels.html 的频道
我对 redis 和所有这些东西都很陌生,起初我让 redis 在端口 6379 上工作,但它是与我过去在开发环境中进行一些测试的系统的主要用户,而不是用户django 应用程序。因此,我为 django 应用程序用户执行了另一个命令在端口 6479 上运行 docker,这似乎有效。然后我有 404 错误,但这是因为 nginx 没有为 websocket 正确配置。现在,我遇到了 500 错误。
这是我尝试打开 websocket 时 django 的回溯:
[2019-08-19 12:54:46,857] ERROR: Exception inside application: Connection has been closed by server
File "/opt/knightools/venv/lib/python3.6/site-packages/channels/sessions.py", line 183, in __call__
return await self.inner(receive, self.send)
File "/opt/knightools/venv/lib/python3.6/site-packages/channels/middleware.py", line 41, in coroutine_call
await inner_instance(receive, send)
File "/opt/knightools/venv/lib/python3.6/site-packages/channels/consumer.py", line 59, in __call__
[receive, self.channel_receive], self.dispatch
File "/opt/knightools/venv/lib/python3.6/site-packages/channels/utils.py", line 59, in await_many_dispatch
await task
File "/opt/knightools/venv/lib/python3.6/site-packages/channels_redis/core.py", line 429, in receive
real_channel
File "/opt/knightools/venv/lib/python3.6/site-packages/channels_redis/core.py", line 484, in receive_single
index, channel_key, timeout=self.brpop_timeout
File "/opt/knightools/venv/lib/python3.6/site-packages/channels_redis/core.py", line 327, in _brpop_with_clean
await connection.eval(cleanup_script, keys=[], args=[channel, backup_queue])
Connection has been closed by server
从我在网上看到的情况来看,这可能是一个 redis 配置/安装问题,但是为什么在使用manage.py runserver 运行时它可以正常工作?运行 docker 的正确方法是什么?我看到跟踪从会话开始,所以也许我对它们有问题,但它们正确存储在数据库中(据我所知)。
我完全迷路了,所以如果你能帮助我,谢谢。
【问题讨论】:
-
你按照你写的把redis端口改成6479(一开始是6379)?是否也更改了相应的设置?
-
您好,感谢您的评论。是的,我更改了它们,并根据 djangodeployment 手册重新编译了 settings.py。可以肯定的是,我必须承认我尝试了我设置的所有端口(主用户为 6379,django-app 用户为 6479,root 用户为 6579),每次重新编译以确保它不是从那里开始的。
标签: python django websocket django-channels