SocketIO在自签名证书上抛出net :: ERR_CERT_AUTHORITY_INVALID

时间:2018-10-11 17:10:01

标签: node.js ssl socket.io certificate self-signed

我在客户端上使用套接字io:

const socket = require('socket.io-client')('https://localhost:4200', {secure: true, rejectUnauthorized: false})

在服务器上:

let https = require('https')
let fs = require('fs')

let options = {
    key: fs.readFileSync('cert/my.net.key'),
    cert: fs.readFileSync('cert/my.net.cert'),
    requestCert: false,
    rejectUnauthorized: false,
};

const server = https.createServer(options, require('express')())
const io = require('socket.io')(server)

所有服务均正常启动,但是在客户端上我得到polling-xhr.js:263 GET https://localhost:4200/socket.io/?EIO=3&transport=polling&t=MPa6ZuL net::ERR_CERT_AUTHORITY_INVALID

为什么?怎么了?

1 个答案:

答案 0 :(得分:0)

在代码顶部添加process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";。 这将为您的节点环境禁用HTTPS。

要使其更加安全,请查看此link