【问题标题】:How to debug django channels in production (nginx)?如何在生产环境(nginx)中调试 django 通道?
【发布时间】:2019-09-26 09:22:21
【问题描述】:

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 调试工具栏: Debugging django-channels

但对生产环境没有帮助。

我被卡住了 - 下一步是什么?

【问题讨论】:

    标签: nginx django-channels daphne


    【解决方案1】:

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

    proxy_pass http://0.0.0.0:8001;
    

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

    proxy_pass http://127.0.0.1:8001;
    

    【讨论】:

      猜你喜欢
      • 2020-07-28
      • 2011-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多