sosedoff / pgweb

Cross-platform client for PostgreSQL databases
https://sosedoff.github.io/pgweb
MIT License
8.63k stars 732 forks source link

How to get pgweb to run on a subdomain? #415

Closed majestique closed 5 years ago

majestique commented 5 years ago

I've created a subdomain for my site pgweb.mysite.com

I'd like to attach pgweb to that subdomain, how does one do that?

sosedoff commented 5 years ago

In order to answer your question i'll need some details about your environment, like what web server are you running, where is it hosted, etc.

majestique commented 5 years ago

It's hosted on vultr.com running on CentOS 7.6. Apache isn't running right now.

sosedoff commented 5 years ago

If that VPS does not have any other web services you have 2 options:

  1. Download and install Docker and then start pgweb with docker run -d -p 80:8081 sosedoff/pgweb

  2. Download the precompiled binary from releases page (linux/amd64 version), unpack the archive and start pgweb process with pgweb --bind=0.0.0.0 --listen=80. I haven't used CentOS for a long time so im not sure what kind of system manager it runs, but if it happen to be systemd you can use a service file from here: https://github.com/sosedoff/pgweb/tree/master/config

majestique commented 5 years ago

Ah so pgweb isn't able run with other web services such as apache on the same VPS?

sosedoff commented 5 years ago

It could, it just depends on how you configure apache virtual hosts file. You would still need to start the pgweb on some port (it runs on localhost:8081) and run it in the background. Then Apache would proxy traffic to it from your subdomain.

There's an old comment about how to run pgweb and nginx: https://github.com/sosedoff/pgweb/issues/84#issuecomment-96741961

majestique commented 5 years ago

Beautiful!

Got it working with this in apache:

NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin webmaster@mysite.com
    ServerName mysite.com
    ServerAlias www.mysite.com
    DocumentRoot /var/www/html/
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin me@mysite.com
    ServerName pgweb.mysite.com
    ProxyPreserveHost On

    # setup the proxy
    <Proxy *>
        Order allow,deny
        Allow from all
    </Proxy>
    ProxyPass / http://localhost:8081/
    ProxyPassReverse / http://localhost:8081/
</VirtualHost>

Thank you!

sosedoff commented 5 years ago

Please make sure to password protect your subdomain. You can either enable password in pgweb (pgweb --auth-user=admin --auth-pass=pa$$word) or with apache's htpasswd.