使用Django同時運行UWSGI和ASGI

[英]Run simultaneously UWSGI and ASGI with Django


I'm currently running a Django (2.0.2) server with uWSGI having 10 workers

我目前正在運行一個帶有uWSGI的Django(2.0.2)服務器,有10個工作人員

I'm trying to implement a real time chat and I took a look at Channel. The documentation mentions that the server needs to be run with Daphne, and Daphne needs an asynchronous version of UWSGI named ASGI.

我正在嘗試實現實時聊天,我看了一下Channel。該文檔提到服務器需要與Daphne一起運行,而Daphne需要一個名為ASGI的UWSGI異步版本。

I manged to install and setup ASGI and then run the server with daphne but with only one worker (a limitation of ASGI as I understood) but the load it too high for the worker.

我管理安裝和設置ASGI,然后用daphne運行服務器,但只有一個工作者(我理解的ASGI的限制),但是工作負載太高了。

Is it possible to run the server with uWSGI with 10 workers to reply to HTTP/HTTPS requests and use ASGI/Daphne for WS/WSS (WebSocket) requests ? Or maybe it's possible to run multiples instances of ASGI ?

是否可以使用帶有10個工作程序的uWSGI運行服務器來回復HTTP / HTTPS請求並使用ASGI / Daphne進行WS / WSS(WebSocket)請求?或者也許可以運行ASGI的多個實例?

1 个解决方案

#1


6  

It is possible to run WSGI alongside ASGI here is an example of a Nginx configuration:

可以在ASGI旁邊運行WSGI,這是Nginx配置的一個例子:

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;
    }
}

To use the /ws/ correctly, you will need to enter your URL like that:

要正確使用/ ws /,您需要輸入以下URL:

ws://localhost/ws/your_path

Then nginx will be able to upgrade the connection.

然后nginx將能夠升級連接。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2018/02/14/725f6c37aa71bc3c5cc56f82edf172b5.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com