我正在尝试将Django / Django渠道应用程序部署到VPS。该项目的django部分有效,我可以访问任何URL,并且正在加载模板,但是其中的Django Channels部分无效。每当我尝试到达网络套接字时,我都会得到connection refused
或WebSocket connection to 'ws://54.39.20.155/receiver' failed: Error during WebSocket handshake: Unexpected response code: 404
有人可以帮我发现我在做什么错,并告诉我我需要做什么才能运行Django频道吗?
这是我的设置:
环境:
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.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
添加到您的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;
}