【问题标题】:SequelizeConnectionError: The server does not support SSL connectionsSequelizeConnectionError:服务器不支持 SSL 连接
【发布时间】:2020-07-23 23:15:10
【问题描述】:

我正在尝试将我的项目与 PostgreSQL 连接,但显示此错误。请帮我 我已经安装了 Postgres.app 和 GUI PgAdmin。

Unhandled rejection SequelizeConnectionError: The server does not support SSL connections
        at /Users/inamur/Documents/Project/project-api/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:186:20
        at Connection.connectingErrorHandler (/Users/inamur/Documents/Project/project-api/node_modules/pg/lib/client.js:203:14)
        at Connection.emit (events.js:223:5)
        at Connection.EventEmitter.emit (domain.js:475:20)
        at Socket.<anonymous> (/Users/inamur/Documents/Project/project-api/node_modules/pg/lib/connection.js:90:21)
        at Object.onceWrapper (events.js:313:26)
        at Socket.emit (events.js:223:5)
        at Socket.EventEmitter.emit (domain.js:475:20)
        at addChunk (_stream_readable.js:309:12)
        at readableAddChunk (_stream_readable.js:290:11)
        at Socket.Readable.push (_stream_readable.js:224:10)
        at TCP.onStreamRead (internal/stream_base_commons.js:181:23)

这是我的 .env 文件

JWT_SECRET='UserNews'
DB_LINK='postgres://root:root@localhost:5432/SCROLL001?ssl=true'

这是连接文件。

const sequelize = new Sequelize(process.env.DB_LINK, {
  dialect: 'postgres',
  protocol: 'postgres',
  dialectOptions: {
    ssl: {
      require: 'true'
    }
  }
});

【问题讨论】:

  • 您的数据库是否需要 SSL 连接>
  • @PrabhjotSinghKainth 是的

标签: node.js postgresql express ssl sequelize.js


【解决方案1】:

你没有正确使用 dialectOptions。

只需进行以下更改:

const sequelize = new Sequelize(process.env.DB_LINK, {
  dialect: 'postgres',
  protocol: 'postgres',
  dialectOptions: {
    ssl: true,
    native:true
  }
});

是否使用本机库的本机标志。在'pg'的情况下-将此设置为true将允许SSL支持,默认值为false。 reference link

【讨论】:

  • 感谢您的努力,但对我不起作用
【解决方案2】:

我已经解决了这个问题。

const sequelize = new Sequelize(process.env.DB_LINK, {
  dialect: 'postgres',
  protocol: 'postgres',
  dialectOptions: {}, //removed ssl
});

更改数据库链接

DB_LINK='postgres://root:root@localhost:5432/SCROLL001'

【讨论】:

  • 有人可以指定 btw ssl: false 有什么区别,并像这里提到的那样给出 {} - 空对象:)
【解决方案3】:

建议在生产应用程序中使用 SSL 进行连接。您可以继续使用 SSL 连接,同时使用以下方法在本地绕过它:

const sequelize = new Sequelize(process.env.DB_LINK, {
  dialect: 'postgres',
  protocol: 'postgres',
  ssl: process.env.DB_ENABLE_SSL,
  dialectOptions: {
    ssl: process.env.DB_ENABLE_SSL && {
      require: true
    }
  }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-07-23
    • 2017-10-28
    • 2021-12-17
    • 2020-05-27
    • 1970-01-01
    • 2012-03-08
    • 2016-07-20
    • 1970-01-01
    相关资源
    最近更新 更多