以下为dev环境下配置,正式线上建议使用uwsgi和Daphne不是替代wsgi和asgi
# nginx.conf
# 上面记得配置好证书,这里省略
location / {
#root html;
#index index.html index.htm;
proxy_pass http://127.0.0.1:8000/;
}
# wss代理配置,主要设置http协议header支持websocket
location /ws {
proxy_pass http://127.0.0.1:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
前端代码:
const chatSocket = new WebSocket(
'wss://'
+ window.location.host
+ '/ws/chat/'
+ roomName
+ '/'
);
小demo,可多人ob的单机游戏,家用网络,仅支持ipv6
url里xxx可以改为是房间号,自定义文本,可多人进入同一个房间。