Recently I made chat function with django channels 2.0
It’s bit easy to create function in local, but I encountered obstacle while deploy it to production server.
I have to use asgi
for deploy socket. For that, I use daphne
instead of gunicorn
or uwsgi
.
Install redis in ubuntu
First, just redis. It’s not a hard work.
sudo apt-get install redis-server
# then start server
redis-server start
# can access redis-cli
redis-cli
Install channel_redis
Have to install dependencies just like local’s requirements.txt
pip install -U channels_redis
Add asgi.py
Have to make asgi.py
just beside wsgi.py
"""
ASGI entrypoint. Configures Django and then runs the application
defined in the ASGI_APPLICATION setting.
"""
import os
import django
from channels.routing import get_default_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
django.setup()
application = get_default_application()
use daphne
daphne myproject.asgi:application
for more information about daphne, check here
nginx settings
server {
listen 80;
server_name my_site_name;
client_max_body_size 30M;
# plus your own settings
...
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:8000;
location /ws {
proxy_pass http://127.0.0.1:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
# your settings include /static or /media
...
}
'backend > django' 카테고리의 다른 글
Django: show invalid message in django loginform (0) | 2018.07.23 |
---|---|
Django: add attrs to django form (0) | 2018.07.22 |
Django: use ckeditor in django - django ckeditor (0) | 2018.05.24 |
Django: logout when get for django-allauth (0) | 2018.05.23 |
Django: architect - enhance ORM for make multiple table (0) | 2018.05.21 |