【问题标题】:SocketIO throws net::ERR_CERT_AUTHORITY_INVALID on self signed certificateSocketIO 在自签名证书上抛出 net::ERR_CERT_AUTHORITY_INVALID
【发布时间】:2019-03-16 20:39:19
【问题描述】:

我在客户端使用socket 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

为什么?怎么了?

【问题讨论】:

  • 我有同样的错误,但错误来自我的 Chrome 浏览器。我正在使用带有 nodejs 和 express 的自签名证书。我必须在 Chrome 中单击“继续”才能继续

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


【解决方案1】:

出于安全原因,浏览器不喜欢自签名证书。

为了在您的开发环境中解决这个问题,我看到了三个选项:

  1. 使用认证单位颁发的证书。

  2. 根据开发环境动态创建服务器,不包括证书,直接使用 HTTP 和 WS(而不是 HTTPS 和 WSS)。

  3. 更改您在开发中使用的浏览器的配置,使其接受自签名证书。

    • 例如,对于 Chrome,只需启用 允许从 localhost 加载的资源的无效证书。 (chrome://flags/#allow-insecure-localhost) 设置。

但请记住,您将无法在生产环境中使用自签名证书。

【讨论】:

    猜你喜欢
    • 2018-03-03
    • 1970-01-01
    • 2016-01-31
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 2017-08-06
    • 2016-12-14
    • 1970-01-01
    相关资源
    最近更新 更多