Nodejs中Redis的TLS配置

9

我正在使用ioRedis node包将我的node js应用程序连接到通过TLS保护的redis服务器。我正在使用的Redis版本是Redis 6.0。我的服务器使用证书运行正常,但是在从node应用程序连接时出现错误。

 Redis({
          host: "localhost",
          port: 6379,
          tls: {
            key: fs.readFileSync('./redis.key'),
            cert: fs.readFileSync('./redis.crt'),
            maxVersion: 'TLSv1.3',
            minVersion: 'TLSv1.3',
            ca: [fs.readFileSync('./redis.pem')]
          }
        })

Node.js 应用程序出现错误的原因是

This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
   Error: read ECONNRESET
            at TCP.onStreamRead (internal/stream_base_commons.js:205:27)

尝试从nodejs应用连接时,服务器出现错误。

17:29:44.295 # 错误接受客户端连接:error:1408F10B:SSL routines:ssl3_get_record:wrong version number

目标是仅使用TLS安全性建立redis连接。


我在GitHub上问了同样的问题:https://github.com/luin/ioredis/issues/1076 也许你也可以在那里发表评论。 - Ilkka Oksanen
2个回答

22

我之前也在做同样的事情,我尝试了这种方法(node-redis v2.8.0):

const redis = require('redis');
const fs = require('fs');

const client = redis.createClient({
    host: '<hostname>',
    port: <port>,
    tls: {}
});

不要传递证书密钥和其他内容,尝试将tls作为空对象传递。 使用这种方法的指南如下。 https://docs.upstash.com/docs/howto/connectwithtls


0

我认为你需要指定文件需要读取的编码方式

const redis = require('ioredis');
const fs = require('fs');

const client = redis.createClient({
    host: 'hostName',
    port: 'port',
    tls: {
       key: fs.readFileSync('pathToFile', 'ascii')  /* this is usually the encoding */
       cert: fs.readFileSync('pathToFile', 'ascii')
       ca: fs.readFileSync('pathToFile', 'ascii')  /* this is usually the encoding */
    }

})

在这里查找更多信息


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接