Postgres debian服务器部署错误:主机没有pg_hba.conf条目

时间:2016-02-08 06:44:43

标签: node.js postgresql debian

我在vpn上安装了Postgres(Debian 7.0)。如果我在本地运行node.js服务器并将其连接到远程PG,它的工作绝对完美 但当我将回购邮件发送到vpn并尝试在那里运行node.js服务器时,我收到了这个错误:

error fetching client from pool { [error: no pg_hba.conf entry for host "111.111.11.111", user "postgres", database "production", SSL off]

111.111.11.111 - vpn的ip,其中PG数据库和node.js服务器应该运行。

这是pg_hba.conf

host all all 222.222.222.2/24 trust
# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                peer
#host    replication     postgres        127.0.0.1/32            md5
#host    replication     postgres        ::1/128                 md5

222.222.222.2 - 我的本地机器IP地址

1 个答案:

答案 0 :(得分:1)

您必须将node.js配置为使用 localhost (unix-socket),如果您使用IP地址,则必须添加它,如pg_hab.conf:

host production postgres 111.111.11.111 trust

但出于安全原因,我建议使用其他用户连接到您的数据库,例如:

host production nodejs-user 111.111.11.111 md5

并在psql中创建用户“nodejs-user”