如何在正式版(nginx)中调试Django频道?

时间:2019-05-08 15:28:03

标签: nginx django-channels daphne

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;
}

我确保consumers.py文件包含以下行:

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

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

但这对生产环境没有帮助。

我陷入困境-下一步是什么?

1 个答案:

答案 0 :(得分:0)

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

proxy_pass http://0.0.0.0:8001;

对我来说真的很奇怪-这样行吗?也许:

proxy_pass http://127.0.0.1:8001;