λͺ©. 8μ›” 14th, 2025

D: Self-hosting Supabase gives you full control over your PostgreSQL database, authentication, and real-time APIs. In this guide, we’ll walk through deploying Supabase using Docker and connecting it to a custom domain for API access.


πŸ”§ Prerequisites

Before starting, ensure you have:

  • A Linux server (Ubuntu/Debian recommended)
  • Docker & Docker Compose installed
  • A domain name (e.g., api.yourdomain.com)
  • Basic terminal skills

οΏ½ Step 1: Install Docker & Docker Compose

Run these commands to set up Docker:

# Install Docker
sudo apt update && sudo apt install docker.io

# Install Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

Verify with:

docker --version && docker-compose --version

πŸ‹ Step 2: Deploy Supabase with Docker

Supabase provides an official docker-compose.yml file.

  1. Clone the Supabase repo:

    git clone --depth 1 https://github.com/supabase/supabase
    cd supabase/docker
  2. Edit .env file:
    Modify docker/.env to set:

    POSTGRES_PASSWORD=YourStrongPassword123!
    JWT_SECRET=YourRandomJWTSecretKey
    SITE_URL=https://yourdomain.com
  3. Start Supabase:

    sudo docker-compose up -d

    This launches:

    • PostgreSQL (Port 5432)
    • Studio (Port 3000)
    • Kong API Gateway (Port 8000)

🌐 Step 3: Connect a Custom Domain to Supabase API

To access Supabase APIs via api.yourdomain.com:

Option A: Using Nginx (Recommended)

  1. Install Nginx:

    sudo apt install nginx
  2. Configure a reverse proxy:
    Edit /etc/nginx/sites-available/supabase:

    server {
       listen 80;
       server_name api.yourdomain.com;
    
       location / {
           proxy_pass http://localhost:8000;
           proxy_set_header Host $host;
       }
    }
  3. Enable the config:

    sudo ln -s /etc/nginx/sites-available/supabase /etc/nginx/sites-enabled/
    sudo nginx -t && sudo systemctl restart nginx

Option B: Cloudflare Proxy

If using Cloudflare:

  • Set DNS A record for api.yourdomain.com β†’ Your server IP
  • Enable Proxy (Orange Cloud)

πŸ”’ Step 4: Secure with SSL (HTTPS)

Use Let’s Encrypt for free SSL:

sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d api.yourdomain.com

Auto-renewal:

sudo certbot renew --dry-run

🚦 Step 5: Configure Supabase Client

Update your app’s Supabase client:

import { createClient } from '@supabase/supabase-js'

const supabase = createClient(
  'https://api.yourdomain.com',
  'your-anon-key' // Get from Supabase Studio → Settings → API
)

πŸ›  Troubleshooting

  • Port conflicts? β†’ Edit docker-compose.yml to change ports.
  • Database not starting? β†’ Check logs:
    docker logs supabase-db
  • API Gateway issues? β†’ Restart Kong:
    docker restart supabase-kong

πŸŽ‰ Done!

You now have a self-hosted Supabase with:
βœ… PostgreSQL + Auth
βœ… Realtime APIs
βœ… Custom domain (api.yourdomain.com)
βœ… HTTPS security

For scaling, consider adding load balancing or separate DB backups. Happy coding! πŸ’»πŸ”₯

Pro Tip: Monitor with docker stats and set up automated backups for your database!

λ‹΅κΈ€ 남기기

이메일 μ£Όμ†ŒλŠ” κ³΅κ°œλ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. ν•„μˆ˜ ν•„λ“œλŠ” *둜 ν‘œμ‹œλ©λ‹ˆλ‹€