/
/
Installing Pgweb on a server with ispmanager 6

Installing Pgweb on a server with ispmanager 6

To manage PostgreSQL within the ispmanager 6 control panel, you can use the Pgweb web application.

Pgweb allows you to log in to PostgreSQL not only as a database server administrator but also as an individual user.

To get started, install the Pgweb web client:

curl -s https://api.github.com/repos/sosedoff/pgweb/releases/latest \
| grep linux_amd64.zip \
| grep download \
| cut -d '"' -f 4 \
| wget -qi - \
&& unzip pgweb_linux_amd64.zip \
&& rm pgweb_linux_amd64.zip \
&& mv pgweb_linux_amd64 /usr/local/bin/pgweb

Choose an available port for Pgweb and launch it on that port. For example, port 3000:

/usr/local/bin/pgweb --listen=3000 &

Create a configuration file for Pgweb in the Nginx directory:

touch /etc/nginx/vhosts-includes/pgweb-nginx.conf

Add the following configuration to the file:

location = /pgweb {
    return 301 /pgweb/;
}

location /pgweb/ {
    proxy_pass http://127.0.0.1:3000/;  
    
    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 /pgweb; 
    
    proxy_redirect http://127.0.0.1:3000/ /pgweb/;
    
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    
    proxy_read_timeout 300s;
    proxy_connect_timeout 75s;
    
    proxy_cookie_path / /pgweb;
}

If you specified a different port for Pgweb, update the proxy_pass directive accordingly.

Restart Nginx:

service nginx restart

The Pgweb web interface is now accessible via the /pgweb path on the server's IP address or any website hosted in the panel—for example, https://192.168.0.10/pgweb or https://domain.com/pgweb.

For convenience, you can also create a button to navigate to the Pgweb web interface, which will be available in the Main menu.

To do this, create and configure the necessary files for the control panel. Create the following files:

touch /usr/local/mgr5/etc/xml/ispmgr_mod_pgweb.xml
touch /usr/local/mgr5/addon/myaddon.sh

Add the following configuration to the file /usr/local/mgr5/etc/xml/ispmgr_mod_pg.xml:

<?xml version="1.0" encoding="UTF-8"?>
<mgrdata>
  <mainmenu level="user+">
    <modernmenu>
      <node name="my_pgweb" customicon="/manimg/icons/pg.svg">
              <node name="open_pgweb" function="https://<ip-адрес_сервера>/pgweb"  />
      </node>
    </modernmenu>
  </mainmenu>
  <handler name="myaddon.sh" type="xml">
    <func name="open_pgweb" />
  </handler>
  <lang name="en">
    <messages name="desktop">
      <msg name="modernmenu_my_pgweb">PostgreSQL</msg>
      <msg name="modernmenu_open_pgweb">Pgweb</msg>
    </messages>
  </lang>
</mgrdata>

You can use any website listed in the panel for the function value. In this case, Pgweb will open at that website's address and will be protected by the website's SSL certificate, if installed.

Add a single line to the file /usr/local/mgr5/addon/myaddon.sh:

#!/bin/bash

Restart the panel:

/usr/local/mgr5/sbin/mgrctl -m ispmgr -R