gpt4 book ai didi

postgresql - 无法将 SSL 安全数据库连接到 typeorm

转载 作者:太空宇宙 更新时间:2023-11-03 14:26:26 25 4
gpt4 key购买 nike

这是我第一次使用 NestJS,我无法将托管在 Digitalocean 上的 Postgres 数据库连接到 NestJS。

我在网上搜索解决方案并尝试添加 "ssl": "true"或 "extra": { "ssl": "true"}

这是我的 ormconfig.json

{
"type": "postgres",
"host": "host",
"port": "port",
"username": "username",
"password": "password",
"database": "database",
"extra": {
"ssl": "true"
},
"synchronize": "true",
"logging": "true",
"entities": ["src/**/*.entity.ts", "dist/**/*.entity.js"]
}

我希望它能连接到服务器。我遇到的错误是 [TypeOrmModule] Unable to connect to the database。错误:没有主机“”、用户“”、数据库“”、SSL 关闭的 pg_hba.conf 条目

最佳答案

如果有人有同样的问题,我通过为 ssl 添加一个字段并设置我从 Digital Ocean 获得的 ca 证书来修复它。这是我的 ormconfig 的样子:

module.exports = {
name: 'default',
type: 'postgres',
host: 'host',
port: port,
username: 'username',
password: 'password',
database: 'database',
synchronize: true,
dropSchema: false,
logging: true,
ssl: {
ca: process.env.SSL_CERT,
},
entities: ['src/**/*.entity.ts', 'dist/**/*.entity.js'],
};

关于postgresql - 无法将 SSL 安全数据库连接到 typeorm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56660312/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com