【问题标题】:getting SSL error on GeddyJs using Heroku PG on dev environment在开发环境中使用 Heroku PG 在 GeddyJs 上出现 SSL 错误
【发布时间】:2013-02-20 13:58:11
【问题描述】:

我正在使用 GeddyJs 和 heroku cedar 应用程序部署。我正在为数据库使用 Heroku Postgres 服务。

我已经在 geddyjs 的配置文件中配置了用户名/密码/主机名/dbname,但是当我运行 node app.js 时它会抛出一个错误,因为 no pg_hba.conf 我知道这与访问时未使用 SSL 有关db 远程,但我不知道如何在连接上强制 SSL..

这是错误日志:

error: no pg_hba.conf entry for host "70.199.196.17", user "12345", database "database1", SSL off
    at p.parseE (/Users/mikedevita/Web/Sites/gorelative.com/node/node_modules/pg/lib/connection.js:503:11)
    at p.parseMessage (/Users/mikedevita/Web/Sites/gorelative.com/node/node_modules/pg/lib/connection.js:363:17)
    at Socket.p.attachListeners (/Users/mikedevita/Web/Sites/gorelative.com/node/node_modules/pg/lib/connection.js:86:20)
    at Socket.EventEmitter.emit (events.js:96:17)
    at TCP.onread (net.js:397:14)
[Tue, 05 Mar 2013 22:39:49 GMT] ERROR Worker 843 died.

我的 config/development.js 文件:

var config = {
  detailedErrors: true
, debug: true
, hostname: 'localhost'
, port: 3000
, model: {
    defaultAdapter: 'postgres'
  }
, db: {
    postgres: {
        port: 5432
      , password: 'foobar' 
      , database: 'database1'
      , host: 'ec2-107-21-126-45.compute-1.amazonaws.com'
      , user: '12345'
    }
  }
, sessions: {
    store: 'memory'
  , key: 'sid'
  , expiry: 14 * 24 * 60 * 60
  }
};

module.exports = config;

【问题讨论】:

    标签: node.js postgresql heroku geddy


    【解决方案1】:

    您需要将 ssl: true 添加到您的 postgres 配置中。

    postgres: {
        port: 5432
      , password: 'foobar' 
      , database: 'database1'
      , host: 'ec2-107-21-126-45.compute-1.amazonaws.com'
      , user: '12345'
      , ssl: true
    }
    

    Geddy 只是将这个配置对象传递给 pg 模块。查看pg.client wiki page 了解更多信息。

    【讨论】:

      【解决方案2】:

      如果您尝试从 Heroku 外部连接,则需要使用 SSL 连接。如果使用 SSL 加密,我们只允许来自 Heroku 外部的连接

      error: no pg_hba.conf entry for host "70.199.196.17", user "12345", database "database1", SSL off 表示关闭 SSL 后无法连接。

      另外,您可能正在使用 database1 清理您的数据库名称,但如果您没有这样做,我可以向您保证,您的数据库名称实际上不是 database1。

      您还应该NOT NOT NOT将您的凭据硬编码到一个文件中。从您的环境中读出它们。

      【讨论】:

      • 谢谢,这是为了开发,因为我没有在本地安装 pg。我的凭据存储在我的环境中,就像您已经推荐的那样。我也为了问题的目的更改了我的数据库名称/用户/密码信息
      猜你喜欢
      • 1970-01-01
      • 2021-04-16
      • 1970-01-01
      • 2014-07-14
      • 2011-04-15
      • 2011-08-09
      • 2021-09-18
      • 1970-01-01
      • 2021-05-04
      相关资源
      最近更新 更多