0

django 频道在我的本地服务器和我的生产环境中的开发服务器上工作;但是,我无法让它在生产中响应,也无法让它与以下 Daphne 命令一起工作(dojos 是项目名称):

daphne -b 0.0.0.0 -p 8001  dojos.asgi:channel_layer

以下是命令后发生的示例:

2019-05-08 08:17:18,463 INFO     Starting server at tcp:port=8001:interface=0.0.0.0, channel layer dojos.asgi:channel_layer.
2019-05-08 08:17:18,464 INFO     HTTP/2 support not enabled (install the http2 and tls Twisted extras)
2019-05-08 08:17:18,464 INFO     Using busy-loop synchronous mode on channel layer
2019-05-08 08:17:18,464 INFO     Listening on endpoint tcp:port=8001:interface=0.0.0.0
127.0.0.1:57186 - - [08/May/2019:08:17:40] "WSCONNECTING /chat/stream/" - -
127.0.0.1:57186 - - [08/May/2019:08:17:44] "WSDISCONNECT /chat/stream/" - -
127.0.0.1:57190 - - [08/May/2019:08:17:46] "WSCONNECTING /chat/stream/" - -
127.0.0.1:57190 - - [08/May/2019:08:17:50] "WSDISCONNECT /chat/stream/" - -
127.0.0.1:57192 - - [08/May/2019:08:17:52] "WSCONNECTING /chat/stream/" - -

(forever)

同时在客户端我得到以下控制台信息:

websocketbridge.js:121 WebSocket connection to 'wss://www.joinourstory.com/chat/stream/' failed: WebSocket is closed before the connection is established.
Disconnected from chat socket

我感觉问题出在 nginx 配置上,所以这是我的配置文件服务器块:

location /chat/stream/ {
    proxy_pass http://0.0.0.0:8001;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $http_host;
}


location /static/ {
    root /home/adam/LOCdojos;
}

我确保 consumer.py 文件有这一行:

def ws_connect(message):
    message.reply_channel.send(dict(accept=True))

我尝试为每个问题安装带有通道面板的 django 调试工具栏: 调试 django-channels

但它在生产环境中没有帮助。

我被困住了——下一步是什么?

4

1 回答 1

0

我也遇到了这种问题,但是:

proxy_pass http://0.0.0.0:8001;

对我来说看起来很奇怪 - 它是这样工作的吗?也许:

proxy_pass http://127.0.0.1:8001;
于 2019-06-06T10:41:04.393 回答