node.js - 无法使用 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.0
ip 连接,因为当我在本地机器上使用 mac os 运行相同的应用程序时,它工作得非常好。
我尝试了几种方法,例如拥有 nginx 代理、添加 ssl 连接等。但似乎没有任何效果。
如果有人可以帮助我解决这个问题,我将不胜感激。完全封锁!
解决方案
推荐阅读
- sql - 我已经在 SAS 中编写了这个查询,但它选择的记录比预期的要多
- extjs - 在工作区中创建构建
- vba - Excel VBA:将数据从工作表移动到工作簿/每张工作表创建一个新工作簿
- sql - 从存储过程中删除列名
- filter - imagmagick:根据 r/g/b 条件选择性地填充像素?
- php - 如何在php中用引号分隔数据
- oracle - 将 Varchar2 的返回值从默认(4000)更改为(10char)?
- java - 仅映射 JoinTable 关系中的一列
- javascript - 如何从 HTML 加载带有 cookie 的资源
- sql-server - SQL Server - 有人可以解释这个查询吗?