django - 在 nginx 上部署 django channel

标签 django nginx redis django-channels daphne

我对 nginx 以及如何配置它来运行 channel 一无所知。我的环境是django 2.x ubuntu 16 nginx daphne redis digitalocean 我已经对我的 nginx 配置文件进行了数周的修改,现在无法连接我的套接字。

nginx 配置

server {
  listen 80;
  server_name x.x.x.x;

  location = /favicon.ico { access_log off; log_not_found off; }

  location /static/ {
    alias /home/admin1/myproject/channels-examples/multichat/static/ ;
  }

  location / {
    include proxy_params;
    proxy_pass http://unix:/home/admin1/myproject/channels-examples/multichat/multichat.sock
  }
}

我将不胜感激任何帮助。

最佳答案

您需要通过 daphne 运行您的应用(您可以在此处阅读更多信息:https://channels.readthedocs.io/en/latest/deploying.html)并为 websockets 连接配置相关的 nginx 部分:

location / {
    proxy_pass http://127.0.0.1:8000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
  }

关于django - 在 nginx 上部署 django channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52023012/

相关文章:

node.js - 我的服务器在 nginx 代理上运行 Node JS 时出现 502 Bad Gateway 错误

python - uWSGI 和 Django - 运行 wsgi 时出错

node.js - 将端口 443 用于 Socket.IO 是个坏主意吗?

python - 在 ModelForm 中仅将日期时间字段显示为小时和分钟(不显示日期)

plugins - 用于窗口的 nginx 粘性模块

ruby-on-rails - Rails ActionCable 中出现 "Unable to find subscription with identifier"的原因是什么?

flask - 多个同时使用的单个 Redis 实例

Redis 键卡在 -1 的 TTL

django - Sorl-thumbnail:升级到新版本

python - 是否有 django 的 'hello world' 网站?或者(我已经安装了 django,现在是什么)?