node.js - Heroku、Node.js、PostgreSQL 主机错误 : no pg_hba. conf 条目

标签 node.js postgresql heroku

我的 Heroku 应用程序一周前崩溃了,我已经排查了 3 天但没有成功。尝试将连接代码更改为 ssl,并对 pg_hba.conf 和 postgresql.conf 文件进行了一些更改,但没有成功。

这是不断出现的错误:

ConnectionError [SequelizeConnectionError]: no pg_hba.conf entry for host "", user "", database "", SSL off
    at /app/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:182:24
    at Connection.connectingErrorHandler (/app/node_modules/pg/lib/client.js:194:14)
    at Connection.emit (events.js:210:5)
    at Socket.<anonymous> (/app/node_modules/pg/lib/connection.js:134:12)
    at Socket.emit (events.js:210:5)
    at addChunk (_stream_readable.js:308:12)
    at readableAddChunk (_stream_readable.js:289:11)
    at Socket.Readable.push (_stream_readable.js:223:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:182:23) {
  name: 'SequelizeConnectionError',
  parent: error: no pg_hba.conf entry for host "52.206.229.39", user "pirotuslftnuae", database "d7q6mo0trncmiq", SSL off
      at Connection.parseE (/app/node_modules/pg/lib/connection.js:614:13)
      at Connection.parseMessage (/app/node_modules/pg/lib/connection.js:413:19)
      at Socket.<anonymous> (/app/node_modules/pg/lib/connection.js:129:22)
      at Socket.emit (events.js:210:5)
      at addChunk (_stream_readable.js:308:12)
      at readableAddChunk (_stream_readable.js:289:11)
      at Socket.Readable.push (_stream_readable.js:223:10)
      at TCP.onStreamRead (internal/stream_base_commons.js:182:23) {
    name: 'error',
    length: 167,
    severity: 'FATAL',
    code: '28000',
    detail: undefined,
    hint: undefined,
    position: undefined,
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'auth.c',
    line: '496',
    routine: 'ClientAuthentication'
  },

 const db = new Sequelize({
      user: "name",
      password: "****",
      database: "databaseName",
      port: 5432,
      host: "localhost",
      ssl: true,
      dialect: 'postgres',
      dialectOptions: {
        "ssl": {"rejectUnauthorized": false}
      }
    });

# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD
  host  all             all             0.0.0.0/0                md5
# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow rep

# - Connection Settings -

#listen_addresses = '*'         # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for all
                                        # (change requires restart)
port = 5432                             # (change requires restart)
max_connections = 100                   # (change requires restart)
#superuser_reserved_connections = 3     # (change requires restart)
unix_socket_director`enter code here`ie

最佳答案

我终于用数据库文件中的这个 ssl 代码解决了我的问题

let config

if (process.env.DATABASE_URL) {
  config = {
    logging: false,
    ssl: true,
    dialectOptions: {
      ssl: {
        require: true,
        rejectUnauthorized: false
      }
    }
  }
} else {
  config = {
    logging: false
  }
}

const db = new Sequelize(
  process.env.DATABASE_URL ||
    `postgres://localhost:5432/${databaseName}`,
  config
)

关于node.js - Heroku、Node.js、PostgreSQL 主机错误 : no pg_hba. conf 条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67351970/

相关文章:

heroku - 将 docker 容器从外部注册表部署到 Heroku

javascript - 如何从 Node 控制台查看 html?

mysql - 在Linux(Kubuntu)上从MySQL迁移到PostgreSQL

java - Heroku 找不到 webapp-runner.jar

sql - 在 PostgreSQL 中对组内的行进行排序

postgresql - 在表中保留一定数量的记录

ssl - 在 Heroku 服务器上部署 golang martini HTTPS

javascript - 为什么 Sails JS 无法识别我的自定义策略?

node.js - Webpack 配置 - 为什么我们使用 path.resolve 进行输出而不是输入?

javascript - node.js(快速框架): require and post