我可以配置connect-pg-simple以启用SSL吗?

问题描述 投票:1回答:2

我在Heroku上运行Postgres数据库和节点应用程序。当我尝试做的时候

app.use(session({
  store: new pgSession({
    conString: process.env.DATABASE_URL
  }),
  secret: 'my-super-secret-session',
  resave: false,
  cookie: {
    maxAge: 7 * 24 * 60 * 60 * 1000
  }
}));

我得到了一个投诉:error: no pg_hba.conf entry for host "1.2.3.4", user ,myuser", database "mydb", SSL off

我想我需要告诉connect-pg-simple以某种方式使用SSL?

postgresql session heroku connect
2个回答
2
投票

如果你无法编辑pg_hba.conf,因为你正在使用像heroku这样的服务,试试这个。

你所要做的就是用conString替换conObject并指定connectionStringssl选项。

app.use(session({
  store: new pgSession({
    conObject: {
      connectionString: process.env.DATABASE_URL,
      ssl: true,
    },
  }),
  secret: 'my-super-secret-session',
  resave: false,
  cookie: {
    maxAge: 7 * 24 * 60 * 60 * 1000
  }
}));

1
投票

您需要在pg_hba.conf中添加一个条目以允许您的连接。

例:

vi $PGDATA/pg_hba.conf
host    all             all             1.2.3.4/32           md5

保存此配置文件后,您需要通过发出config reload命令重新加载它:

pg_ctl reload

然后重试连接。

© www.soinside.com 2019 - 2024. All rights reserved.