我如何在生产中运行Django通道?

问题描述 投票:0回答:1

我在VPS上部署了一个简单的Django应用,这是我的环境:

virtualenv
gunicorn
nginx
systemd

一切正常,我可以看到我的模板正在加载。我还添加了一个小的Django Channels功能,但是该部分不起作用。因此,尽管我可以在WSGI上毫无问题地使用它,但是如果我尝试联系使用方,则会收到错误消息。所以我的问题是:如何在生产中也运行频道?

这是我目前的工作:

/ etc / nginx / sites-available / myproject

server {
        listen 80;
        server_name 54.39.20.155;

        location = /favicon.ico { access_log off; log_not_found off; }
        location /static/ {
            root /WaitingRoomVenv/WaitingRoom/WaitingRoom/static;
        }

        location / {
            include proxy_params;
            proxy_pass http://unix:/WaitingRoomVenv/WaitingRoomEnv.sock;
        }
    }

/ etc / systemd / system / gunicorn.service

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=root
Group=www-data
WorkingDirectory=/WaitingRoomVenv/WaitingRoom
ExecStart=/WaitingRoomVenv/WaitingRoomEnv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/WaitingRoomVenv/WaitingRoomEnv.sock WR.wsgi:application

[Install]
WantedBy=multi-user.target

要开始使用“ gunicorn:sudo systemctl start gunicorn要启动nginx:sudo systemctl restart nginx

python django nginx gunicorn django-channels
1个回答
1
投票

要访问channesl,您需要运行daphne之类的ASGI服务器(随通道提供),而不要使用您正在使用的WSGI geunicorn,请参阅:

https://channels.readthedocs.io/en/latest/deploying.html

启动服务器daphne -p 8001 myproject.asgi:application,然后在您的nginx中,您需要代理传递给端口8001

© www.soinside.com 2019 - 2024. All rights reserved.