我正在尝试配置 Django channel 以在我的 ubuntu 服务器( digital ocean )上运行。
我在 6379 端口
上运行了 redis-server。
Daphne 正在监听端点 unix:/home/mysite/sockets/mysite.sock
并启用了 HTTP/2 支持
(不确定在这个阶段是否需要)
我还有一个 ./manage.py runworker
监听。
我的达芙妮运行命令是
daphne -u /home/mysite/sockets/mysite.sock project.asgi:channel_layer
我的 http 请求通过(在 daphne 日志中)就像它们在我的本地环境中一样,例如
#local
127.0.0.1:62241 - - [09/Oct/2017:21:03:41] "GET /playground/channel-simple" 200 1826
#server (side note. not sure why port + host are eliminated here.?)
None - - [09/Oct/2017:21:53:51] "GET /playground/channel-simple" 200 1622
但是,当我通过 js 请求 websocket url 时,一切都崩溃了......
#local
127.0.0.1:62268 - - [09/Oct/2017:21:03:43] "WSCONNECTING /chat/private-room/" - -
127.0.0.1:62268 - - [09/Oct/2017:21:03:43] "WSCONNECT /chat/private-room/" - -
#server
None - - [09/Oct/2017:21:54:04] "GET /chat/private-room/" 404 86
它看起来像是将请求视为 http 请求而不是 websocket 连接?这也是js控制台日志...
#server - js response to connection
WebSocket connection to 'ws://[MY-IP]/chat/private-room/' failed: Error during WebSocket handshake: Unexpected response code: 404
任何人都可以建议这个 404 可能在哪里被解雇吗?或有关调试的任何提示。
谢谢。
最佳答案
我已经解决了这里的问题,现在它已按预期在服务器上运行。我还没有完成 nginx 配置。菜鸟 :).
以下文章很有用。
https://www.nginx.com/blog/websocket-nginx/
http://masnun.rocks/2016/11/02/deploying-django-channels-using-daphne/
关于ubuntu - Django Channels 服务器配置 : Ubuntu. 404 握手,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46643149/