配置思路
- 使用Nginx+uwsgi来部署项目的http请求相关
- 使用Nginx+daphne来部署项目的websocket的请求部分,详细的是uwsgi对asgi不友好
uwsgi配置
[uwsgi]
http=127.0.0.1:8006
dir=/test
module=test.wsgi
master=true
processes=1
vacuum=true
enable-threads = true
preload=true
lazy-apps=true
buffer-size=65536
http-websockets = true
daemonize = /var/log/test.log
Nginx配置
server {
listen 8000;
server_name 127.0.0.1:8000;
charset UTF-8;
access_log /var/log/nginx/myweb8006_access.log;
error_log /var/log/nginx/myweb8006_error.log;
root /test/web/dist;
client_max_body_size 75M;
location /ws {
proxy_pass http://127.0.0.1:8001;
proxy_http_version 1.1;
proxy_read_timeout 3600s;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
supervisor+Daphne来运行asgi
[program:daphne]
directory=/test
command=daphne -b 127.0.0.1 -p 8001 --proxy-headers test.asgi:application
autostart=true
autorestart=true
stdout_logfile=/tmp/websocket.log
redirect_stderr=true