首页 > 解决方案 > 无法使用 node-postgres 从 ec2 实例连接到 pg 数据库

问题描述

我正在尝试从托管在 ec2 实例上的 nodejs express 应用程序查询 pg 数据库。我正在使用node-postgres图书馆。但是,我收到此错误:

error: no pg_hba.conf entry for host "xxx.xx.xx.xxx", user "xyz", database "db_name", SSL off
at Connection.parseE (/home/ec2-user/express/node_modules/pg/lib/connection.js:553:11)
at Connection.parseMessage (/home/ec2-user/express/node_modules/pg/lib/connection.js:378:19)
at Socket.<anonymous> (/home/ec2-user/express/node_modules/pg/lib/connection.js:119:22)
at Socket.emit (events.js:182:13)
at Socket.EventEmitter.emit (domain.js:442:20)
at addChunk (_stream_readable.js:283:12)
at readableAddChunk (_stream_readable.js:264:11)
at Socket.Readable.push (_stream_readable.js:219:10)
at TCP.onread (net.js:639:20)

现在我明白这可能是一个简单的问题。我的理解是 postgres 服务器上的 pg_hba.conf 文件只允许0.0.0.0ip 连接,因为当我在本地机器上使用 mac os 运行相同的应用程序时,它工作得非常好。

我尝试了几种方法,例如拥有 nginx 代理、添加 ssl 连接等。但似乎没有任何效果。

如果有人可以帮助我解决这个问题,我将不胜感激。完全封锁!

标签: node.jspostgresqlamazon-ec2node-postgres

解决方案


推荐阅读