项目中使用了webscoket进行实时通讯,但是生产环境又使用了django+nginx+uwsgi的部署方式,我们都知道uwsgi并不能处理websocket请求,所以需要asgi服务器来处理websocket请求,官方推荐的asgi服务器是daphne
1. 部署daphne
使用pip install daphne 的方式安装
项目配置文件目录(settings.py同级)下创创建文件asgi.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") # myproject ==> 项目名称
django.setup()
application = get_default_application()
启动daphne 测试是否正常运行(成功以后退出)
daphne -b 127.0.0.1 -p 8001 devops.asgi:application # devops ==> 项目名称
2.安装supervisor
supervisor是由pytho