Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strapi CMS, Heroku error: no pg_hba.conf entry for host

Three months ago, I created an Strapi App that has deployed on Heroku, and everything works fine. I used macOS 10.13.6 and node 14.15.4 for the local environment

The configuration of database was created inside a file named database.js which located in rootApp/config/env/production/database.js The following are everything config inside these file (database.js):

const parse = require('pg-connection-string').parse;
const config = parse(process.env.HEROKU_POSTGRESQL_MAROON_URL);
module.exports = ({ env }) => ({
  defaultConnection: 'default',
  connections: {
    default: {
      connector: 'bookshelf',
      settings: {
        client: 'postgres',
        host: "ec2-35-169-184-61.compute-1.amazonaws.com",
        port: 5432,
        database: "d3d9tcukxxx",
        username: "mwtwuvkwxxxx",
        password: "42f0337xxxxx",
      },
      options: {
                ssl:true,
      },
    },
  },
});

But after 3 months (right now), I checked from heroku logs --tail then these app getting an error and the message was:

error error: no pg_hba.conf entry for host "3.86.36.125", user "mwtwuvkwtrqpir", database "d3d9tcukrk5fgh", SSL off

I used Strapi 3.2.5 , and I was deployed on Heroku Postgres with Plan free (Hobby). I hope everyone helping me for this questions, and hope helping others for same case. Thank you

like image 256
Yues Hafiyan Avatar asked Mar 13 '21 15:03

Yues Hafiyan


1 Answers

We had the same issue on our Heroku instances and just recently found a fix.

Adding rejectUnauthorized to the database config appears to work.

config/database.js

module.exports = ({ env }) => ({
  defaultConnection: 'default',
  connections: {
    default: {
      connector: 'bookshelf',
      settings: {
        client: 'postgres',
        host: env('DATABASE_HOST', 'localhost'),
        port: env.int('DATABASE_PORT', 5432),
        database: env('DATABASE_NAME', 'strapi'),
        username: env('DATABASE_USERNAME', 'strapi'),
        password: env('DATABASE_PASSWORD', 'strapi'),
        schema: env('DATABASE_SCHEMA', 'public'), // Not Required
        ssl: {
          rejectUnauthorized: env.bool('DATABASE_SSL_SELF', false), // For self-signed certificates
        },
      },
      options: {
        ssl: env.bool('DATABASE_SSL', false),
      },
    },
  },
});

I cannot take full credit however, it was this post on the Strapi forum that led me to the answer: https://forum.strapi.io/t/error-no-pg-hba-conf-entry-for-host-ssl-off/3409

subsequently this link: https://strapi.io/documentation/developer-docs/latest/setup-deployment-guides/configurations.html#database

like image 167
Luke Holland Avatar answered Nov 06 '22 21:11

Luke Holland