Run simultaneously UWSGI and ASGI with Django
我目前正在使用具有10个工作程序的uWSGI运行Django(2.0.2)服务器
我正在尝试实现实时聊天,并查看了Channel。
该文档提到服务器需要与Daphne一起运行,并且Daphne需要UWSGI的异步版本ASGI。
我安装并设置了ASGI,然后使用daphne运行服务器,但只有一个工作程序(据我所知,这是ASGI的局限性),但是对于工作程序来说负载太高了。
是否可以使用带有10名工作人员的uWSGI来运行服务器,以回复HTTP / HTTPS请求并将ASGI / Daphne用于WS / WSS(WebSocket)请求?
或者,也许可以运行ASGI的多个实例?
可以将WSGI与ASGI一起运行,这是Nginx配置的示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | server { listen 80; server_name {{ server_name }}; charset utf-8; location /static { alias {{ static_root }}; } # this is the endpoint of the channels routing location /ws/ { proxy_pass http://localhost:8089; # daphne (ASGI) listening on port 8089 proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection"upgrade"; } location / { proxy_pass http://localhost:8088; # gunicorn (WSGI) listening on port 8088 proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 75s; proxy_read_timeout 300s; client_max_body_size 50m; } } |
要正确使用
1 | ws://localhost/ws/your_path |
然后,nginx将能够升级连接。