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 ภาษาไทย
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.
Type your own values and the commands on this page follow
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#
mkdir -p ~/n8n && cd ~/n8n
umask 077
echo "N8N_ENCRYPTION_KEY=$(openssl rand -hex 32)" > .envservices:
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_DOMAIN {
reverse_proxy n8n:5678
}Start it#
docker compose up -d
docker compose logs -f caddyOpen 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.
docker compose pull n8n
docker compose up -d n8nBack up#
Stop n8n briefly so the SQLite file is complete.
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 n8nCopy 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 |
| 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.