可能是什么问题,我得到这个错误“错误:无效的WebSocket框架:RSV1必须清除”?
我使用socket.io包连接到Node.js,代码如下。
let app = express();
const http = require("http").createServer(app);
const io = require("socket.io")(http, /*options*/);
io.on('connection', function (socket) {
console.log('a user connected');
socket.conn.on('upgrade', ()=>{
const upgradedTransport = socket.conn.transport.name;
});
socket.conn.on('upgrade', ()=>{
const upgradedTransport = socket.conn.transport.name;
});
socket.on('create or join', function (room) {...});
socket.on('ready', function (room) {...});
socket.on('candidate', function (event){...});
.....
.....
socket.on('hangup', function (room) {
socket.leave(room);
socket.emit('hangup', room);
});
});
});
下面是我的Nginx配置,
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream websocket {
server 127.0.0.1:1337;
}
server {
server_name mydomain.subdomain.com;
root /usr/share/nginx/html;
include /etc/nginx/default.d/*.conf;
underscores_in_headers on;
location /socket.io/ {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:1337;
# this magic is needed for WebSocket
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location / {
proxy_pass http://127.0.0.1:8094;
}
listen [::]:443 ssl ipv6only=on;
listen 443 ssl;
ssl_certificate ...
ssl_certificate_key /etc/...;
include /etc/...;
ssl_dhparam /etc/...;
}
server {
if ($host = mydomain.subdomain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name mydomain.subdomain.com;
return 404;
}
向 Postman 提出要求时,握手详情如下,
握手详细信息
Request URL: https://mydomain.subdomain.com/socket.io
Request Method: GET
Status Code: 101 Switching Protocols
Request Headers
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: 3DlYbOFVRGepjPrOd92Zew==
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Host: mydomain.subdomain.com
型
同样响应报头,
Server: nginx/1.14.0 (Ubuntu)
Date: Tue, 10 May 2022 12:50:41 GMT
Connection: upgrade
Upgrade: websocket
Sec-WebSocket-Accept: FB8P5FMN8gPIsHjfRrrIoe+9+OI=
可能是什么问题,我得到这个错误“错误:无效的WebSocket框架:RSV1必须安全”?谢谢你帮我。
1条答案
按热度按时间wecizke31#
您可以在请求头中看到特定WebSocket扩展的设置-消息压缩:
我认为默认情况下,WebSocket客户端会对消息进行压缩,但它接收到的 Dataframe 不包含压缩位,因此会导致:
很可能是服务器中没有配置相关的压缩设置。因此,当您创建WebSocket Server时,请尝试将以下选项传递给它:
型
你可以看到错误在以后会消失。