PGAdmin4 configured behind a reverse proxy but unable to connect to Postgresql server

21 Views Asked by At

I installed Posgresql 16 server on a Debian 11 host that I access through SSH, and all works as expected when I use PSQL cli. Then I installed and configured PGAdmin4 Web, and I configured NGINX with reverse proxy so I can access to PGAdmin4 web interface from a browser.

The firewall is correctly configured.

The NGINX directives are as follow:

    location /pgadmin4/ {
         proxy_pass http://127.0.0.1:80/pgadmin4/;
         proxy_redirect off;
         proxy_set_header Host $host;
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_set_header X-Forwarded-Proto $scheme;

         proxy_set_header X-Script-Name /pgadmin4;
         proxy_buffering off;
    }

I can access to PGAdmin4 web interface through an URL: https://<mydomain_name>/pgadmin4/

The problem is that I am unable to connect to the Postgresql server through the Server Dialog, I systematically get an error message: Unable to connect to server: connection timeout expired.

In file /usr/pgadmin4/web/config.py, I replaced DEFAULT_SERVER = '127.0.0.1' by DEFAULT_SERVER = '0.0.0.0'.

In file /etc/postgresql/16/main/pg_hba.conf, I added the below line: host all all 0.0.0.0/0 md5

In the PGAdmin4 Dialog box I configured the following options (let's assume that the host name is example.tld):

Connection tab:

  • Host name/address: example.tld
  • Maintenance database: postgres
  • Username: postgres

SSH Tunnel tab:

  • Tunnel host: example.tld
  • Tunnel port: 22
  • Username: pgadmin (regular Unix user)
  • Authentication: Password

I also created a new database (bookstore) with that I can access directly under user 'pgadmin' from a shell with the below command, and modified the connection tab accordingly:

psql -U pgadmin -d bookstore -h 127.0.0.1 -p 5432 -W

I read countless documentation online but still no luck.

I am stuck and any help would be appreciated.

I tried the configuration with different databases and users in the Connection tab where I have no issue with PSQL. When I try to use the port 5432, I immediately get an error message, see below: Cannot use port 5432 because behind a reverse proxy on port 80

In the SSH Tunnel tab, when I use a non-existent user (e.g. test) or a wrong password, I have a different error message:Error when a wrong user or wrong password is used

0

There are 0 best solutions below