【问题标题】:Can I configure connect-pg-simple to have SSL on?我可以将 connect-pg-simple 配置为启用 SSL 吗?
【发布时间】:2016-12-31 16:07:04
【问题描述】:

我正在 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


    【解决方案1】:

    如果您无法编辑 pg_hba.conf,因为您使用的是 heroku 之类的服务,请试试这个。

    您所要做的就是将conString 替换为conObject 并指定connectionString 和ssl 选项。

    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
      }
    }));
    

    【讨论】:

    • 感谢您的解决方案,但是,在应用它之后,我现在收到了 Failed to prune sessions: self signed certificate 。我正在使用 Heroku postgres
    【解决方案2】:

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

    例子:

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

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

    pg_ctl reload
    

    然后重试连接。

    【讨论】:

    猜你喜欢
    • 2016-03-30
    • 2012-07-09
    • 2014-12-21
    • 1970-01-01
    • 2015-07-12
    • 2010-09-06
    • 2018-09-16
    • 2015-06-17
    • 2019-08-08
    相关资源
    最近更新 更多