Self-host n8n on a VPS with Docker and HTTPS

A ready Compose file with Caddy for HTTPS, plus updates and backups

The XVer team 1 min read 25 min to do Intermediate

Also in ภาษาไทย

On this page
  1. Before you start
  2. Create the files
  3. Start it
  4. Update
  5. Back up
  6. Fix common problems
  7. Questions

n8n runs on a VPS from one Docker Compose file, with Caddy issuing and renewing the HTTPS certificate. Start with 2 vCPU and 2 GB of RAM, or 4 GB if your workflows handle large files.

Before you start#

  • An Ubuntu server with Docker Engine and the Compose plugin
  • A DNS A record for your domain pointing at the server
  • Ports 80 and 443 open

Create the files#

Terminal
mkdir -p ~/n8n && cd ~/n8n
umask 077
echo "N8N_ENCRYPTION_KEY=$(openssl rand -hex 32)" > .env
~/n8n/compose.yaml
services:
  caddy:
    image: caddy:2
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy_data:/data
    depends_on:
      - n8n

  n8n:
    image: docker.n8n.io/n8nio/n8n
    restart: unless-stopped
    environment:
      N8N_HOST: N8N_DOMAIN
      N8N_PROTOCOL: https
      N8N_PROXY_HOPS: "1"
      WEBHOOK_URL: https://N8N_DOMAIN/
      N8N_ENCRYPTION_KEY: ${N8N_ENCRYPTION_KEY}
      GENERIC_TIMEZONE: Asia/Bangkok
      TZ: Asia/Bangkok
    volumes:
      - n8n_data:/home/node/.n8n

volumes:
  caddy_data:
  n8n_data:
~/n8n/Caddyfile
N8N_DOMAIN {
    reverse_proxy n8n:5678
}

Start it#

Terminal
docker compose up -d
docker compose logs -f caddy

Open https://N8N_DOMAIN and create the owner account right away: the first visitor sets it up.

Update#

Back up and read the n8n release notes first. In production, pin a version instead of latest.

Terminal
docker compose pull n8n
docker compose up -d n8n

Back up#

Stop n8n briefly so the SQLite file is complete.

Terminal
cd ~/n8n
docker compose stop n8n
docker run --rm -v n8n_n8n_data:/data:ro -v "$PWD":/backup alpine tar czf /backup/n8n-$(date +%F).tar.gz -C /data .
docker compose start n8n

Copy the archive and .env off the server, to separate places.

Fix common problems#

Symptom Fix
Webhooks show localhost Check WEBHOOK_URL, then docker compose up -d
No HTTPS Check DNS, ports 80 and 443, and the Caddy log
Schedules run at the wrong time Set GENERIC_TIMEZONE

Questions#

Is self-hosted n8n free?

The Community Edition is available under the Sustainable Use License, which limits offering it as a service. Read the terms before commercial use; you still pay for the server.

Do I need PostgreSQL?

Start with SQLite. Move to PostgreSQL when many workflows run at once or you want queue mode.

What size of server?

2 GB of RAM for one person and small payloads; 4 GB or more for files or tens of thousands of rows per run.

PlanNVMe diskBandwidthPer hourPer month
2 vCPU · 2 GB40 GB4 TB฿0.47/hr฿279/mo
2 vCPU · 4 GB40 GB4 TB฿0.70/hr฿419/mo
4 vCPU · 8 GB80 GB10 TB฿1.37/hr฿819/mo

Prices from XVer billing when this page was built

Follow the guide on your own server

Create a Cloud Server with Ubuntu, Debian or Windows Server, billed by the hour in Thai baht. Support answers 24/7 in Thai and English.