Nginx + Uwsgi无法使Websocket适应我的Django 我用Django写一些url_patterns,例如
http://[host]:[port]/events
我需要处理一个websocket
<ws://[host]:[port]/alarm>
Nginx收听10001和uwsgi收听10002 我已经在我的nginx.conf中添加了一些
server
{
listen 10001;
root /xxx;
location /alarm {
include uwsgi_params;
uwsgi_pass 127.0.0.1:10002;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
}
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:10002;
uwsgi_read_timeout 60;
}
......
但是它仍然不起作用,当我看到浏览器时,我看到了
Status Code:404 Not Found
我选择uwsgi来实现我的websocket,在测试中,我写了这个
ws.create_connection("ws://127.0.0.1:10001/alarm")
然后我用它来启动我的应用
uwsgi --init uwsgi.ini --http_websockets
我在uwsgi输出中看到了这一点
GET /alarm => generated 77 bytes in 6 msecs (HTTP/1.1 404) 6 headers in 207 bytes (1 switches on core 0)
web_client.py在下面给了我错误
Handshaken 404
我的uwsgi.ini是这个
WEBSOCKET_FACTORY_CLASS="dwebsocket.backends.uwsgi.factory.uWsgiWebSocketFactory"
http = :8008
socket = :10002
在我的django中,我写了这个
application = ProtocolTypeRouter({
'websocket':AuthMiddlewareStack(
URLRouter(
alarm.routing.channel_routing
)
),
那我的错在哪里?