node js https net::ERR_SSL_VERSION_OR_CIPHER_MISMATCH

问题描述 投票:0回答:1

我实现了以下代码来使 Node js 在 https 上运行

const https = require('https');
const options = {
        key: fs.readFileSync('apache key file path.key', "UTF-8"),
        crt: fs.readFileSync('apache crt file path.crt', "UTF-8")

}
const httpsvr = https.createServer(options, (req, res) => {
       res.writeHead(200, { 'Content-Type': 'text/plain' });
       res.end('TEST HTTPS\n');
});

const io = require('socket.io')(httpsvr);

httpsvr.listen(8443);

io.on("connect_error", (err) => {
    console.log('connect error ' + err.message );
});

io.on('connection', function (socket) {
   socket.on('TestNodeEvent', function (data) {
     console.log(data);
     console.log('io8443 connected');
   });
});`

这运行了https服务器。但是客户端无法建立socket.io连接。因此广播不会发生

socket = io('https://xxx.xxx.xxx.xx:8443');
socket.on('testupdate', function (data) `

我尝试向其他用户发送页面刷新信号,但套接字 io 连接不正确。 我从浏览器中收到以下错误

Chrome - net::ERR_SSL_VERSION_OR_CIPHER_MISMATCH

Firefox -
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at      https://xxx.xxx.xxx.xx:8443/socket.io/?EIO=4&transport=polling&t=OfUXCGt. (Reason: CORS request did not succeed). Status code: (null).

`

Node JS version  - v14.21.3
socket.io        - 4.2.0
socket.io-client - 4.2.0

我想让其他用户进行页面刷新,同时使用选择应该来自其他用户的特定选项

这就是我在后端执行 culr 和 openssl 时得到的结果

openssl s_client -connect xxx.xxx.xxx.xxx:8443
CONNECTED(00000003)
139917842872128:error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:ssl/record/rec_layer_s3.c:1544:SSL alert number 40
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 7 bytes and written 289 bytes
Verification: OK
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
Early data was not sent
Verify return code: 0 (ok)
---

node.js linux apache ssl socket.io
1个回答
0
投票

如果您在 ubuntu 上使用 Apache 或 nginx,您应该将代码修改为

const https = require('https');
对于 HTTPS 服务器,请使用 CERTBOT 首先尝试安装 certbot,成功安装后运行此命令(如果您使用的是 apache

sudo certbot --apache

或者如果你正在使用 nginx

sudo certbot --nginx
© www.soinside.com 2019 - 2024. All rights reserved.