【问题标题】:deploy django channels on nginx在 nginx 上部署 django 频道
【发布时间】:2019-02-01 00:42:49
【问题描述】:

我对 nginx 以及如何配置它来运行频道一无所知。我的环境是django 2.xubuntu 16nginxdaphneredisdigitalocean我已经修改了我的nginx配置文件一个星期,现在无法让我的套接字连接。

nginx config

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

我将非常感谢任何帮助。

【问题讨论】:

    标签: django nginx redis django-channels daphne


    【解决方案1】:

    您需要通过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";
      }
    

    【讨论】:

    • 你知道为什么我去 143.x.x.x:8000 静态文件不通过吗?
    【解决方案2】:

    我在非托管 VPS 上遇到了类似问题。

    查看这个repository,这是我在发现什么对我有用时创建的。

    您的静态位置:

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

    应该是这样的:

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

    【讨论】:

      猜你喜欢
      • 2021-07-30
      • 2021-04-03
      • 2013-07-04
      • 2019-12-17
      • 2020-05-07
      • 2019-08-18
      • 2019-07-19
      • 2012-09-02
      • 2020-04-26
      相关资源
      最近更新 更多