Most "best VPS for n8n" posts are vendor pages that stop at docker run. The parts that actually break a self-hosted n8n come later: webhook URLs that say localhost, schedules that fire at New York time, and a restored database whose credentials will not decrypt. This post builds a production-shaped setup (n8n, PostgreSQL and Caddy in one Compose file) and covers sizing, backups, updates and when to reach for queue mode. Commands assume Ubuntu 24.04 LTS or Debian 12 with Docker Engine and the Compose v2 plugin; env var names are checked against docs.n8n.io as of 24 November 2026.
Read the licence first
Self-hosted n8n is free, but it is not OSI open source. It uses the Sustainable Use License, and n8n's licence FAQ allows internal business use, personal projects and consulting ("consulting and automation services are explicitly permitted"). What it does not allow is hosting n8n as a service where your clients build their own workflows, or white-labelling it. If you are building automations for clients on your own instance, you are fine.
Sizing: RAM follows the data, not the workflow count
n8n does not publish a single minimum for a plain instance. Its memory guide explains why: memory use grows with the size of JSON payloads, binary files, the Code node, manual test runs in the editor and how many executions run at once. Fifty workflows that each move a few kilobytes between APIs use less than one workflow that parses a 200 MB CSV.
What the docs do say: the Docker Compose guide asks for at least 4 GB of RAM and 2 vCPUs for its stack with the optional n8n Assistant sandbox, and the Hetzner guide says its smallest plan (CPX11) "is enough" for most usage without Assistant.
Reasonable starting points (ours, not n8n's):
| Load | Start with |
|---|---|
| One person or small team, API-to-API workflows, Postgres | 2 vCPU, 4 GB |
| Files, PDFs, large spreadsheets, AI agent workflows, many Code nodes | 4 vCPU, 8 GB |
| Webhook bursts or long jobs delaying other runs | Queue mode with workers (below) |
Then measure. docker stats --no-stream after a busy day tells you more than any table. Use a full virtual machine (KVM or similar) rather than an OpenVZ/LXC container, where Docker's networking and storage drivers often cannot load the kernel features they need.
Disk grows with execution history. By default n8n prunes executions older than 336 hours (14 days) and keeps at most 10,000, controlled by EXECUTIONS_DATA_MAX_AGE and EXECUTIONS_DATA_PRUNE_MAX_COUNT (executions variables).
SQLite or Postgres
SQLite is the default and needs nothing extra. n8n's production requirements recommend PostgreSQL for production, and queue mode does not support SQLite. The database page lists PostgreSQL 16, 17 and 18 as supported. Moving from SQLite later is a migration, so if more than one person will build workflows, start on Postgres.
Prepare the server
Install Docker from Docker's own apt repository (Ubuntu, Debian), then check with docker compose version. Point an A record such as n8n.example.com at the server.
Open only SSH, HTTP and HTTPS (on Debian 12, sudo apt install ufw first):
sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw allow 443/udp
sudo ufw enable
UDP 443 is for HTTP/3, which Caddy enables by default.
One trap: Docker's firewall documentation says Docker and ufw use firewall rules in ways that make them incompatible: published container ports skip ufw rules. So the Compose file below never publishes 5678 or 5432. Only Caddy publishes ports, and it reaches n8n over the internal Compose network.
The Compose stack: n8n, Postgres, Caddy
n8n's production requirements say to terminate TLS at a reverse proxy and not to expose n8n directly; they name Nginx and Caddy as examples, and the Hetzner guide uses Caddy. Caddy gets and renews Let's Encrypt certificates on its own, so it is the shortest path.
mkdir -p ~/n8n/conf ~/n8n/backups && cd ~/n8n
cat > .env <<EOF
N8N_DOMAIN=n8n.example.com
N8N_ENCRYPTION_KEY=$(openssl rand -hex 32)
POSTGRES_PASSWORD=$(openssl rand -hex 24)
EOF
chmod 600 .env
compose.yaml:
services:
postgres:
image: postgres:18
restart: unless-stopped
environment:
POSTGRES_USER: n8n
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: n8n
volumes:
- pg_data:/var/lib/postgresql
healthcheck:
test: ["CMD-SHELL", "pg_isready -U n8n -d n8n"]
interval: 10s
timeout: 5s
retries: 5
n8n:
image: n8nio/n8n:2.48.8
restart: unless-stopped
environment:
DB_TYPE: postgresdb
DB_POSTGRESDB_HOST: postgres
DB_POSTGRESDB_PORT: "5432"
DB_POSTGRESDB_DATABASE: n8n
DB_POSTGRESDB_USER: n8n
DB_POSTGRESDB_PASSWORD: ${POSTGRES_PASSWORD}
N8N_HOST: ${N8N_DOMAIN}
N8N_PORT: "5678"
N8N_PROTOCOL: https
N8N_WEBHOOK_URL: https://${N8N_DOMAIN}/
N8N_PROXY_HOPS: "1"
N8N_ENCRYPTION_KEY: ${N8N_ENCRYPTION_KEY}
N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS: "true"
GENERIC_TIMEZONE: Asia/Kolkata
TZ: Asia/Kolkata
volumes:
- n8n_data:/home/node/.n8n
depends_on:
postgres:
condition: service_healthy
caddy:
image: caddy:2
restart: unless-stopped
ports:
- "80:80"
- "443:443"
- "443:443/udp"
environment:
N8N_DOMAIN: ${N8N_DOMAIN}
volumes:
- ./conf:/etc/caddy
- caddy_data:/data
- caddy_config:/config
depends_on:
- n8n
volumes:
pg_data:
n8n_data:
caddy_data:
caddy_config:
Two notes on the database service. From PostgreSQL 18 the official image keeps its data under a versioned directory, and its image docs say to mount /var/lib/postgresql, not the old /var/lib/postgresql/data. And the POSTGRES_* variables only apply when the data directory is empty, so changing the password in .env later does not change it in the database.
The Caddyfile, with the flush_interval -1 that n8n's Hetzner guide uses so streamed responses are not buffered. The site address reads N8N_DOMAIN from the container's environment (Caddyfile environment variables), so the domain lives only in .env. The quoted 'EOF' stops the shell from expanding {$N8N_DOMAIN} itself:
cat > conf/Caddyfile <<'EOF'
{$N8N_DOMAIN} {
reverse_proxy n8n:5678 {
flush_interval -1
}
}
EOF
docker compose up -d
docker compose logs -f n8n
Open https://n8n.example.com and create the owner account immediately: until you do, anyone who finds the URL can claim the instance. 2.48.8 was the stable release on n8n's changelog when this was written; pin whatever is current rather than latest.
The variables that matter behind a proxy
Webhook URL. n8n builds webhook URLs from N8N_PROTOCOL, N8N_HOST and N8N_PORT. Behind a proxy that produces the internal port, not the public 443. The reverse proxy page says to set N8N_WEBHOOK_URL and N8N_PROXY_HOPS=1. Version detail: N8N_WEBHOOK_URL exists from n8n 2.30.0; older releases use WEBHOOK_URL, which the endpoints reference marks as deprecated from 2.35.0 (it still works but logs a warning).
Proxy hops. N8N_PROXY_HOPS is "number of reverse-proxies n8n is running behind" (deployment variables). With it set, n8n trusts X-Forwarded-*. Caddy's reverse_proxy sets X-Forwarded-For, X-Forwarded-Proto and X-Forwarded-Host by default and proxies WebSockets, which the editor uses. If you add Cloudflare's proxy in front, that is a second hop.
Timezone. GENERIC_TIMEZONE drives Schedule Trigger and other time-based nodes and defaults to America/New_York. Without it, "every day at 09:00" runs at 18:30 or 19:30 IST depending on US daylight saving. TZ sets the container's system clock for logs and scripts. Set both to Asia/Kolkata.
Encryption key. Every saved credential is encrypted. If N8N_ENCRYPTION_KEY is unset, n8n generates a random key on first launch and writes it to the config file in /home/node/.n8n. n8n's backup docs are blunt: without that key, a restored database cannot decrypt credentials. Setting it in .env means the key lives in a file you can also store in a password manager. If you are adding the variable to an existing instance, copy the existing key from config instead of generating a new one, or every credential breaks.
Backups
Three things make a full restore: the Postgres database, the n8n_data volume (config file, key, any filesystem binary data) and .env.
cd ~/n8n
docker compose exec -T postgres pg_dump -U n8n -d n8n -Fc > backups/n8n-db-$(date +%F).dump
docker volume ls | grep n8n_data # Compose prefixes the folder name: n8n_n8n_data
docker run --rm -v n8n_n8n_data:/data:ro -v "$PWD/backups":/backup alpine \
tar czf /backup/n8n-data-$(date +%F).tar.gz -C /data .
For moving workflows between instances, the CLI exports each workflow and credential as separate JSON (use separate folders). The files land inside the container, so copy them out to the host folder afterwards:
docker compose exec -u node n8n mkdir -p /home/node/.n8n/backups/workflows /home/node/.n8n/backups/credentials
docker compose exec -u node n8n n8n export:workflow --backup --output=/home/node/.n8n/backups/workflows/
docker compose exec -u node n8n n8n export:credentials --backup --output=/home/node/.n8n/backups/credentials/
docker compose cp n8n:/home/node/.n8n/backups ./backups/cli-$(date +%F)
Credentials stay encrypted, so they only import where the same key is set. The export leaves out users, execution history, variables and settings, so it does not replace the full backup.
~/n8n/backups now holds the database dump, the volume tarball and the JSON exports. Copy that folder and .env off the server. A dump that never left the VPS is not a backup.
Test a restore occasionally on a scratch server, in a ~/n8n folder (so the volume is again named n8n_n8n_data) holding the same compose.yaml, conf/Caddyfile, .env and backups. The .env must carry the same N8N_ENCRYPTION_KEY. n8n's backup docs say to stop n8n before restoring, so this sequence keeps it stopped until the data is back:
docker compose create # containers and volumes, nothing running
docker compose up -d --wait postgres # start only Postgres and wait for its healthcheck
docker compose exec -T postgres pg_restore --clean --if-exists -U n8n -d n8n < backups/n8n-db-YYYY-MM-DD.dump
docker run --rm -v n8n_n8n_data:/data -v "$PWD/backups":/backup alpine \
tar xzf /backup/n8n-data-YYYY-MM-DD.tar.gz -C /data
docker compose up -d
On a stack that is already running, run docker compose stop n8n first and docker compose start n8n at the end.
Updating safely
Take the backups above (or a VPS snapshot), read the release notes, especially the 3.0 breaking changes before moving off 2.x, change the image tag, then run the sequence from n8n's own guides:
docker compose pull
docker compose down
docker compose up -d
Never add -v to down: it deletes named volumes, including your database. n8n's production requirements also note that from n8n 3.0 npm installations are no longer supported, so a Docker setup like this one is the path forward.
Queue mode, briefly
By default one process serves the editor, receives webhooks and runs every execution. Queue mode hands executions to Redis and separate workers. Requirements: Postgres (SQLite is not supported), Redis via QUEUE_BULL_REDIS_HOST and QUEUE_BULL_REDIS_PORT, EXECUTIONS_MODE=queue on the main instance and every worker, and the same N8N_ENCRYPTION_KEY everywhere. A worker is the same image started with the worker command, running 10 jobs at once by default (--concurrency changes it). Turn on Redis persistence, because queued jobs live there. For one team's automations, a single instance on Postgres is usually enough.
A data-residency note for Indian users
Workflow executions often carry personal data: form submissions, CRM records, WhatsApp messages. Self-hosting on a server in Mumbai or Delhi NCR keeps n8n's database and execution history in India, which makes your data map simpler. It does not keep data in India once a workflow sends it to a SaaS API hosted elsewhere. The DPDP Act, 2023 has no general localisation rule (section 16 lets the government restrict transfers to notified countries), but sector rules such as RBI's payment data storage still apply. Lower EXECUTIONS_DATA_MAX_AGE if you do not need weeks of payloads sitting in the database. This is general information, not legal advice.
Common failures
-
Webhook URLs show
localhost:5678:N8N_WEBHOOK_URLis missing. Add it, rundocker compose up -d, then unpublish and republish workflows whose triggers register webhooks with outside services. -
502 from Caddy: n8n is still starting, was killed for memory, or the Caddyfile names the wrong service. Check
docker compose psanddocker compose logs n8n. - No certificate: DNS does not point at the server yet, or port 80 is blocked.
-
Credentials fail after a redeploy: a different encryption key, or a volume removed with
down -v. - "JavaScript heap out of memory": batch the data, split into sub-workflows, or add RAM.
For transparency, this post is from Bigdomainhost, an Indian host with KVM VPS plans in Mumbai (BOM-1) and Delhi NCR (DEL-1). The fuller version with FAQs is in our guide to self-hosting n8n on a VPS in India.
Written by the Bigdomainhost team with AI assistance; facts checked against the linked sources.
Top comments (1)
Good write-up — the two traps you called out (N8N_WEBHOOK_URL and the encryption key) are the ones that actually cost people a day. Three smaller things I'd add:
Your restore step extracts the volume tarball as root (
docker run --rm -v n8n_n8n_data:/data ... tar xzf), so the files come back owned by root. WithN8N_ENFORCE_SETTINGS_FILE_PERMISSIONS="true"the container then exits at start because it can't write.n8n/config. Add--user 1000:1000to that alpine run (orchown -R 1000:1000 /dataafter extracting).Republishing only re-registers webhooks n8n knows about. After a domain change, third-party registrations still point at the old host — Telegram
setWebhook, a Stripe endpoint, a Slack app request URL, an Airtable automation. Those need to be set again by hand, and they need the production URL, not the one the editor's Test button hands out.Give the n8n service its own healthcheck (e.g.
wget -qO- http://localhost:5678/healthz) and hang Caddy'sdepends_onoff it. Otherwise Caddy is up before n8n answers and the first thing you see afterup -dis a 502.The point about keeping the key somewhere off the server is the one worth repeating: a recreated container without that key means every saved credential has to be entered again.