I have a Ruby on Rails
application running on nginx server (application server is on Red Hat OS). The database is installed on another server (same OS: Red Hat).
From console of the application server, I'm able to connect to the database using same db credentials as in application. But the ruby application is not able to make a connection. It is throwing error
The error log /var/log/nginx/error.log
has below error message
stderr:
PG::ConnectionBad (could not connect to server: Permission denied
Is the server running on host "10.178.61.135" and accepting
TCP/IP connections on port 5432?
):
Also, to mention I'm able to run the rake db:migrate
successfully
The database.yml
file looks like below:
production:
adapter: postgresql
encoding: unicode
database: applicationdatabase
host: 10.178.61.135
pool: 30
port: 5432
timeout: 10000
username: dbuser
password: dbpassword
On Database server the connection config /var/lib/pgsql/11/data/pg_hba.conf
:
# Allow replication connections from localhost, by a user with the replication privilege.
local replication all peer
host replication all 127.0.0.1/32 ident
host replication all ::1/128 ident
host all all 0.0.0.0/0 md5
Database privilege
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
---------------------+-------------+----------+-------------+-------------+-----------------------------
applicationdatabase | dbuser | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/dbuser +
| | | | | dbuser=CTc/dbuser
Other configs and versions
# Web app Server
nginx/1.10.1
Phusion passenger 5.0.29
Ruby 2.1.9
Rails 4.1.5
pg 0.17.1
RHEL 7.7
# DB Server
PostgreSQL 11.3
RHEL 7.7