Django 通道和 nginx - 握手期间出错

Django channels and nginx - error during handshake

我正在尝试将 Django/Django 频道应用程序部署到 VPS。该项目的 Django 部分有效,我可以访问任何 url 并且模板正在加载,但它的 Django Channels 部分不起作用。每当我尝试访问 websocket 时,我要么得到 connection refused 要么 WebSocket connection to 'ws://54.39.20.155/receiver' failed: Error during WebSocket handshake: Unexpected response code: 404

谁能帮我找出我做错了什么,并告诉我我需要做什么才能 运行 Django Channels?

这是我的设置:

环境:

virtualenv
django
django-channels
gunicorn
nginx
systemd

/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.服务

[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

添加到您的nginx.conf

location /receiver {
    proxy_pass http://unix:/WaitingRoomVenv/WaitingRoomEnv.sock;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;
}