I'm trying to deploy a Django/Django Channels application to a VPS. The django part of the project works, i can visit any url and the templates are loading, but the Django Channels part of it doesn't work. Whenever i try to reach the websocket i either get connection refused or WebSocket connection to 'ws://54.39.20.155/receiver' failed: Error during WebSocket handshake: Unexpected response code: 404
Can someone help me find what i'm doing wrong and tell me what do i need to do in order to run Django Channels?
Here is my setup:
Environment:
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
To start gunicorn: sudo systemctl start gunicorn
To start nginx: sudo systemctl restart nginx
Add to your 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;
}