NewCode CLOUD — 20% off your first month on all cloud VPSClaim

Self-Hosted Supabase on Hong Kong VPS: Open-Source Firebase (2026)

· 3 min read

Supabase is the open-source Firebase alternative — PostgreSQL + GoTrue authentication + S3-compatible file storage + real-time subscriptions, all with auto-generated REST and GraphQL APIs. Self-hosting on a Hong Kong VPS puts your Supabase instance at CN2 GIA latency for mainland Chinese users, eliminates per-seat pricing ($25/month/user on Supabase Pro), and keeps all user data on infrastructure under your control.


What Self-Hosted Supabase Includes

Component What it does Technology
PostgreSQL 15 Main database PostgreSQL + pgvector + pg_cron
PostgREST Auto REST API from DB schema Haskell REST server
GoTrue Authentication (email, OAuth, magic link) Go auth server
Storage API S3-compatible file storage Node.js + MinIO/local
Realtime WebSocket DB change subscriptions Elixir Phoenix
Studio Web dashboard (table editor, SQL editor) Next.js
Kong API gateway routing all services Kong Gateway

Step 1: Clone and Configure

<code">git clone --depth 1 https://github.com/supabase/supabase
cd supabase/docker
cp .env.example .env

Step 2: Configure .env

<code"># .env — critical settings to change
POSTGRES_PASSWORD=YOUR_STRONG_POSTGRES_PASSWORD
JWT_SECRET=YOUR_RANDOM_64_CHAR_JWT_SECRET
ANON_KEY=GENERATE_WITH_SUPABASE_CLI_OR_ONLINE_TOOL
SERVICE_ROLE_KEY=GENERATE_WITH_SUPABASE_CLI_OR_ONLINE_TOOL

# Your HK VPS public URL (used in emails, OAuth redirects)
SITE_URL=https://supabase.yourdomain.com
API_EXTERNAL_URL=https://supabase.yourdomain.com

# SMTP for auth emails
SMTP_HOST=smtp.yourprovider.com
SMTP_PORT=587
SMTP_USER=noreply@yourdomain.com
SMTP_PASS=SMTP_PASSWORD
SMTP_SENDER_NAME=YourApp
SMTP_ADMIN_EMAIL=admin@yourdomain.com

# Enable email confirmation
ENABLE_EMAIL_AUTOCONFIRM=false
ENABLE_PHONE_AUTOCONFIRM=false

# Studio access (password-protect the dashboard)
DASHBOARD_USERNAME=admin
DASHBOARD_PASSWORD=STRONG_DASHBOARD_PASS

# Storage (local filesystem or S3-compatible)
STORAGE_BACKEND=file
GLOBAL_S3_BUCKET=supabase-storage

# JWT expiry
JWT_EXPIRY=3600

Step 3: Generate JWT Keys

<code"># Generate ANON_KEY and SERVICE_ROLE_KEY from JWT_SECRET using Node.js
node -e "
const jwt = require('jsonwebtoken');
const secret = 'YOUR_JWT_SECRET';
const anon = jwt.sign({role:'anon',iss:'supabase',iat:1713000000,exp:9999999999}, secret);
const service = jwt.sign({role:'service_role',iss:'supabase',iat:1713000000,exp:9999999999}, secret);
console.log('ANON_KEY='+anon);
console.log('SERVICE_ROLE_KEY='+service);
"
# Paste the output values into .env

Step 4: Start Supabase

<code">docker compose up -d

# Check all services are running
docker compose ps
# Expected: supabase-db, supabase-auth, supabase-rest, supabase-storage,
#           supabase-realtime, supabase-studio, supabase-kong — all Up

# Initial startup takes 2-3 minutes
docker compose logs supabase-db -f  # Wait for "database system is ready"

Step 5: Nginx Reverse Proxy

<code">cat > /etc/nginx/sites-available/supabase << 'EOF'
server {
    listen 443 ssl http2;
    server_name supabase.yourdomain.com;
    ssl_certificate /etc/letsencrypt/live/supabase.yourdomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/supabase.yourdomain.com/privkey.pem;

    # All Supabase services routed through Kong (port 8000)
    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_read_timeout 300s;
        proxy_send_timeout 300s;
        client_max_body_size 100m;  # Allow file uploads
    }
}

# Studio dashboard on separate subdomain
server {
    listen 443 ssl http2;
    server_name studio.yourdomain.com;
    ssl_certificate /etc/letsencrypt/live/supabase.yourdomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/supabase.yourdomain.com/privkey.pem;

    # Restrict studio to office IP
    allow YOUR_OFFICE_IP;
    deny all;

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Proto https;
    }
}
EOF
ln -s /etc/nginx/sites-available/supabase /etc/nginx/sites-enabled/
certbot --nginx -d supabase.yourdomain.com -d studio.yourdomain.com
nginx -t && systemctl reload nginx

Step 6: Connect Your Application

<code"># JavaScript/TypeScript (same client as Supabase Cloud)
import { createClient } from '@supabase/supabase-js'

const supabase = createClient(
  'https://supabase.yourdomain.com',
  process.env.SUPABASE_ANON_KEY!
)

// Query with auto-generated REST API
const { data, error } = await supabase
  .from('products')
  .select('id, name, price, category')
  .eq('active', true)
  .order('created_at', { ascending: false })
  .limit(20)

// Auth
const { data: { user } } = await supabase.auth.signUp({
  email: 'user@example.com',
  password: 'SecurePass123!'
})

// Realtime subscription
supabase
  .channel('orders')
  .on('postgres_changes',
    { event: 'INSERT', schema: 'public', table: 'orders' },
    (payload) => console.log('New order:', payload.new)
  )
  .subscribe()

// File upload
const { data } = await supabase.storage
  .from('avatars')
  .upload('user_123/avatar.png', file, { contentType: 'image/png' })

Step 7: Backups

<code"># Daily PostgreSQL backup
cat > /opt/backup-supabase.sh << 'EOF' #!/bin/bash BACKUP_DIR=/backup/supabase/$(date +%Y%m%d) mkdir -p $BACKUP_DIR # Dump database docker exec supabase-db pg_dumpall -U postgres \ | gzip > $BACKUP_DIR/postgres.sql.gz

# Backup storage files
tar czf $BACKUP_DIR/storage.tar.gz /var/lib/docker/volumes/supabase_storage/_data/

# Keep 14 days
find /backup/supabase -maxdepth 1 -mtime +14 -exec rm -rf {} +
echo "Supabase backup completed: $BACKUP_DIR"
EOF
chmod +x /opt/backup-supabase.sh
crontab -l | { cat; echo "0 3 * * * /opt/backup-supabase.sh"; } | crontab -

Conclusion

Self-hosted Supabase on a Hong Kong VPS provides the complete Firebase-alternative stack — PostgreSQL database, JWT authentication, S3-compatible file storage, WebSocket real-time subscriptions, and an auto-generated REST API — at a fixed monthly VPS cost rather than Supabase Cloud’s per-seat pricing. For Asia-Pacific applications, the HK location means the Supabase API endpoint responds at CN2 GIA latency for mainland Chinese users, and all user data remains on infrastructure you control rather than in US data centres.

Self-host your backend: Browse Server.HK Hong Kong VPS plans — a 4 GB plan comfortably runs self-hosted Supabase for up to a few thousand active users.

Related articles

More in VPS & ServersServer setup guides