连接到Heroku PostgreSQL数据库时validation错误
我正在开发一个使用PostgreSQL的Node.js应用程序,并在Heroku上托pipe。 我的问题是,我得到这样的authentication错误:
14:32:05 web.1 | { [error: no pg_hba.conf entry for host "193.40.244.196", user "username", database "database_name", SSL off] 14:32:05 web.1 | length: 168, 14:32:05 web.1 | name: 'error', 14:32:05 web.1 | severity: 'FATAL', 14:32:05 web.1 | code: '28000', 14:32:05 web.1 | detail: undefined, 14:32:05 web.1 | hint: undefined, 14:32:05 web.1 | position: undefined, 14:32:05 web.1 | internalPosition: undefined, 14:32:05 web.1 | internalQuery: undefined, 14:32:05 web.1 | where: undefined, 14:32:05 web.1 | file: 'auth.c', 14:32:05 web.1 | line: '483', 14:32:05 web.1 | routine: 'ClientAuthentication' }
这可能是一个SSL问题,但不应该在这里提到。 SSL应该支持开箱即用。 所以我很难过,只能问什么可能会导致这个错误?
我不确定是否需要在我的系统上编辑pg_hba.conf,但我甚至找不到它。
自己做这个,这是一个简单的修复。 只需通过HTTPS连接即可
通过在Heroku上设置PGSSLMODE
( http://www.postgresql.org/docs/9.0/static/libpq-envars.html )来解决这个问题。 它告诉PostgreSQL默认为SSL。
$ heroku config:set PGSSLMODE=require
node-postgres在它的javascript绑定中不支持SSL,如果你这样做的话就使用它:
var pg = require('pg');
要获得SSL,您需要通过执行以下操作来使用本地绑定:
var pg = require('pg').native;
当您的应用程序在Heroku中运行时,您不需要使用SSL,只需使用SSL进行远程连接(当您的应用程序在本地运行时)。
我添加了这些参数,现在可以从外部服务器连接到我的heroku postgres实例,具体来说,在节点快递服务器中configurationknex.js:
var knex = require('knex')({ client: 'postgres', connection: 'postgres://username:password@host:5432/yourdbname?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory' });
跑到同样的问题。 只是在数据库参数中启用ssl = true。
var pg = require('pg'); var params = { host: 'heroku_hostname',user: 'username',password: 'password',database: 'database',ssl: true }; var client = new pg.Client(params); client.connect();
- Nodemailer不断拒绝无效login身份validation(不使用Gmail)
- 将护照openID-stategy与智威汤逊结合在一起
- 在NodeJS中使用REST APIauthentication困惑
- 如何从basicAuth(Express)注销
- Firebase 3.3.x Nodejs – createUserWithEmailAndPassword不是一个函数
- NodeJS / Firebase承诺的范围
- 如何工作deploydauthentication用户
- 会话身份validationtypes错误:对象#属性“types”<ServerResponse>不是函数
- Passport身份validationcallback不传递req和res