Skip to content

Instantly share code, notes, and snippets.

@tigawanna
Last active September 1, 2024 16:29
Show Gist options
  • Save tigawanna/299ac92da605d3135b33670df6559d66 to your computer and use it in GitHub Desktop.
Save tigawanna/299ac92da605d3135b33670df6559d66 to your computer and use it in GitHub Desktop.
How to host pocketbase on linux with ngnix as a reverse proxy

Tips on linux vm hosting of pocketbase

- copy installer to machine

helper script

#!/usr/bin/env bash
# Transfers a file from local to remote
PATH_TO_FILE=$1
IP=$2
USERNAME=$3
PATH_TO_SSH_KEY=$4
if [ $# -lt 3 ]; then
    echo 'Usage: 0-transfer_file PATH_TO_FILE IP USERNAME PATH_TO_SSH_KEY'
elif [ "$#" -eq 3 ]
then
    scp -o StrictHostKeyChecking=no $PATH_TO_FILE "$USERNAME@$IP:~/"
else
    scp -o StrictHostKeyChecking=no -i $PATH_TO_SSH_KEY $PATH_TO_FILE "$USERNAME@$IP:~/"
fi

example usage

./0-transfer_file pocketbase 18.206.13.229 ubuntu ~/.ssh/id_rsa  

- add nginx reverse proxy config inside

/etc/nginx/conf.d

eg pb.conf

server {
  listen 80;
  server_name pb.tigawanna.tech;

  location / {
      # check http://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive
      proxy_set_header Connection '';
      proxy_http_version 1.1;
      proxy_read_timeout 360s;

      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_pass http://127.0.0.1:8090;
  }
}

- test for errors and reload nginx

sudo nginx -t
sudo nginx -s reload

optionannly add a pb_public with a html file inside it which will be displayed when you hit your provided URL in this case : pb.tigawanna.tech

pb.tigawanna.tech/_/ : fr admin panel and pb.tigawanna.tech/api : for rest pai access

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment