我遵循了关于如何在PostgreSQL和ReactJS前端上创建NodeJS后端的指南,该前端运行良好,请参见here for more。
Qude的js池对象如下所示:
const Pool = require('pg').Pool
const pool = new Pool({
user: 'my_user',
host: 'localhost',
database: 'my_database',
password: 'postgres',
port: 5432,
});我尝试使用SSL加密对PostgreSQL Web服务器执行同样的操作。这个问题没有标记为postgresql,因为对于MySQL和其他数据库来说,这个池看起来是一样的。它也没有标签Linux,因为它应该在其他操作系统上同样工作。
如何从javascript中的Pool类创建一个池对象,该对象可以使用SSL连接到PostgreSQL后端?
发布于 2021-09-11 10:23:16
您需要保存证书,并将其命名为server-certificate.pem,它位于从/开始的静态路径(~,因为用户的主目录不工作)。因此,你需要把它移到一个静态的地方。
我将文件复制到新创建的目录certificates中,但这当然取决于您。您将需要超级用户的权利。
/etc/certificates/server-certificate.pem您需要加载fs并在SSL部分中使用它,参见How to establish a secure connection (SSL) from a Node.js API to an AWS RDS。
const Pool = require('pg').Pool
const fs = require('fs');
const pool = new Pool({
user: 'my_user',
host: 'my_host',
database: 'my_database',
password: 'my_password',
port: 22222,
ssl: {
ca: fs
.readFileSync("/etc/certificates/server-certificate.pem")
.toString()
}
});https://stackoverflow.com/questions/69142073
复制相似问题