Reputation: 1257
I deployed a simple Django app to a VPS, here is my environment:
virtualenv
gunicorn
nginx
systemd
Everything works perfectly, i can see my template loading. I also added a small Django Channels feature, but that part doesn't work; so while i can use it on WSGI without any problem, if i try to reach a Consumer, i will get an error. So my question is: how can i run Channels too in production?
Here is what i currently did:
/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
Upvotes: 0
Views: 1908
Reputation: 2408
To access channesl you need to run through a ASGI server like daphne (that ships with channels) instead of WSGI geunicorn you are using, see:
https://channels.readthedocs.io/en/latest/deploying.html
to start the server daphne -p 8001 myproject.asgi:application
then in your nginx you need to proxy pass to port 8001
Upvotes: 1