django - 客户端发送 ws://[host]:[port]/path 到服务器,我的服务器是 Nginx+uwsgi+Django,但是当我启动 get to server 时总是遇到 404 错误
问题描述
Websocket 不能被 Nginx+Uwsgi 接受到我的 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
)
),
那么我的错在哪里?
解决方案
推荐阅读
- asp.net-mvc - 如何知道 Kendo grid.savechanges() 方法是成功还是失败
- image-processing - 使用计算机视觉对冰箱瓶进行库存管理
- javascript - 如何从nodejs中的firebase存储中解压缩图像?
- javascript - 事件侦听器中的 if 语句不适用于 JavaScript
- linux - 无法使用 url 将数据从 sql server 备份到 azure blob 容器
- javascript - 在使用 Axios 的 Node.js 代码上出现 Request failed 404 错误
- reactjs - 在 material-ui 自动完成字段中断功能上添加拼写检查器
- wordpress - Wordpress 从 url 设置缩略图而不是下载到媒体
- amazon-web-services - SSL_connect 未能执行 TLS 握手
- sh - centos写的脚本在crontab中不起作用的原因