Why self host n8n instead of paying for the cloud?
When you self host n8n, you run the same workflow automation tool on your own server instead of renting it from n8n. The trade is simple: n8n Cloud Starter costs €20 a month (billed annually) and caps you at 2,500 workflow executions a month. The self-hosted Community Edition is free, with unlimited executions — you only pay for the server it runs on, and a small VPS is enough for most personal setups. If your workflows poll APIs every few minutes or loop through AI calls, that execution cap is the first thing you will hit, and self-hosting removes it entirely.
There is a catch, and the official docs say it plainly: n8n recommends self-hosting for people who are comfortable managing servers, and points everyone else at n8n Cloud. You become responsible for updates, backups, and security. This guide gives you the production-shaped setup — Docker Compose, Postgres instead of SQLite, automatic HTTPS through Caddy, and backups you can actually restore from — so you take on that responsibility with your eyes open.
Prices and versions in this guide were verified on 20 November 2026. n8n’s current stable release is 2.48.7.
What you need before you start
- A VPS with 2 vCPUs and 4 GB of RAM, running Ubuntu 24.04. n8n’s own Hetzner guide says a small CPX11 instance is enough for most usage — one recent guide puts a suitable VPS at around €5 a month.
- A domain or subdomain, for example
n8n.example.com, with an A record pointing at your VPS IP. It must resolve before you request a certificate. - SSH access with root or sudo, and about 30 minutes.
If you have never provisioned a VPS before, read our VPS setup guide first — it covers the server hardening steps this guide assumes are already done.
The stack you are building
Three containers, one Docker network, and nothing exposed to the internet except ports 80 and 443:
| Service | What it does | Why it is here |
|---|---|---|
| n8n | The workflow editor and execution engine, on port 5678 | The tool itself, pinned to version 2.48.7 |
| Postgres 18 | Stores workflows, credentials, and execution history | n8n’s docs recommend Postgres over SQLite for any instance running around the clock |
| Caddy | Reverse proxy with automatic HTTPS | Terminates TLS and handles WebSockets, so the editor and webhooks just work |
One deliberate omission: n8n’s official Docker Compose guide now bundles a sandbox stack that powers n8n Assistant. That stack runs a privileged Docker-in-Docker container, needs 4 GB of RAM and 2 vCPUs on its own, and n8n says it is for development and testing, not production. This guide leaves it out. You can add it later on a dedicated host if you want the Assistant.
Step 1: Install Docker
SSH into your VPS and install Docker Engine with the official convenience script, then check both binaries report a version:
sudo apt update && sudo apt upgrade -y
curl -fsSL https://get.docker.com | sh
docker --version
docker compose version
Next, open only the ports the setup needs. n8n’s own port 5678 must not face the internet — Caddy is the only public door:
sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
Step 2: Create the project folder and secrets
Everything lives in /opt/n8n. Generate two secrets before you write any config — a Postgres password and the encryption key n8n uses to protect every credential you save:
sudo mkdir -p /opt/n8n/local-files && cd /opt/n8n
openssl rand -hex 20 # Postgres password
openssl rand -hex 32 # N8N_ENCRYPTION_KEY
Save both values somewhere safe right now — a password manager, not a note on the server. If you lose the encryption key, every stored API credential becomes unreadable, and there is no way to recover it.
Create the .env file with your own values. Keep this file out of version control:
N8N_HOST=n8n.example.com
POSTGRES_USER=n8n
POSTGRES_PASSWORD=paste-the-20-byte-hex-value-here
POSTGRES_DB=n8n
N8N_ENCRYPTION_KEY=paste-the-32-byte-hex-value-here
Step 3: Write the Compose file
Create /opt/n8n/compose.yaml. Three details matter here, so read the notes under the file before you start it:
services:
postgres:
image: postgres:18
restart: unless-stopped
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
PGDATA: /var/lib/postgresql/data
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
interval: 10s
timeout: 5s
retries: 5
n8n:
image: docker.n8n.io/n8nio/n8n:2.48.7
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
environment:
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_PORT=5432
- DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
- DB_POSTGRESDB_USER=${POSTGRES_USER}
- DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
- N8N_HOST=${N8N_HOST}
- N8N_PORT=5678
- N8N_PROTOCOL=https
- WEBHOOK_URL=https://${N8N_HOST}/
- N8N_PROXY_HOPS=1
- N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
- GENERIC_TIMEZONE=Africa/Lagos
- TZ=Africa/Lagos
- N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
volumes:
- n8n_data:/home/node/.n8n
- ./local-files:/files
caddy:
image: caddy:2
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- caddy_data:/data
- caddy_config:/config
volumes:
postgres_data:
n8n_data:
caddy_data:
caddy_config:
Three things to notice:
- The version is pinned (
2.48.7), not:latest. n8n ships a new minor version most weeks. Pinning means you update when you choose to, after reading the release notes — not when a container restart happens to pull a new image. - Postgres 18 needs the
PGDATAline. Postgres 18 changed where it stores data by default. WithoutPGDATA, it writes somewhere the volume does not cover and your database starts empty. The official n8n docs flag this explicitly. - n8n publishes no ports. Only Caddy’s 80 and 443 reach the internet. n8n listens on the internal Docker network, and Caddy forwards to it by service name.
The environment variables do specific jobs, and getting them wrong produces the most common self-hosting headaches:
WEBHOOK_URLis the public URL n8n hands out for webhook triggers. If it is wrong or missing, external services get alocalhostURL they cannot reach. It must end with a trailing slash.N8N_PROXY_HOPS=1tells n8n there is exactly one reverse proxy in front of it, so it reads the real client IP and sets secure cookies correctly.GENERIC_TIMEZONEcontrols schedule triggers;TZcontrols what the container’s own clock reports. Set both to your timezone — the example uses Africa/Lagos, so swap in your own.N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=trueis in n8n’s own Docker examples and tightens the permissions on the config file that holds your encryption key.
One variable you will see in older guides and should not set: N8N_RUNNERS_ENABLED. It is deprecated from n8n 2.0 — task runners are on by default now.
Step 4: Add the Caddyfile
Create /opt/n8n/Caddyfile with two lines. Caddy fetches a Let’s Encrypt certificate automatically the first time the domain is hit, and it proxies WebSocket connections by default — which matters, because n8n’s editor uses WebSockets for live execution feedback:
n8n.example.com {
reverse_proxy n8n:5678
}
Replace n8n.example.com with your subdomain. If you want the full Caddy story — automatic HTTPS, staging endpoints, and troubleshooting — see our Caddy reverse proxy guide.
Step 5: Start it and create your owner account
docker compose up -d
docker compose ps
docker compose logs -f n8n
Wait for the logs to settle, then confirm n8n answers its health endpoint from inside the container:
docker compose exec n8n wget -qO- http://localhost:5678/healthz
Open https://n8n.example.com in your browser. The first screen asks you to create the owner account — name, email, and a strong password. This is the admin account for the whole instance, so use a password from your password manager and turn on two-factor authentication in Settings once you are in.
Step 6: Smoke-test your first workflow
Before you build anything real, prove the moving parts work. Create a workflow with a Manual Trigger node connected to a Set node, set one value in the Set node — for example, a string field called hello with the value it works — and click Execute step. You should see your value in the output panel. If it runs, the editor, the database, and the proxy are all doing their jobs.
Now test the part that breaks most often: webhooks. Create a second workflow with a Webhook node set to the GET method and a production URL, activate the workflow, and open its production URL in your browser. If you get a response, WEBHOOK_URL and the proxy are correct. If the URL shows localhost anywhere, go back to Step 3 — your WEBHOOK_URL is wrong.
Backups that actually restore
A backup you have never restored is a hope, not a backup. n8n keeps three things you care about, and you need all three:
- The database. With Postgres, a hot backup is one command:
docker compose exec -T postgres pg_dump -U n8n n8n | gzip > n8n-db-$(date +%F).sql.gz - Workflows and credentials as files. n8n ships export commands for exactly this. Because
./local-filesis mounted at/filesinside the container, the exports land on the host where you can copy them elsewhere:docker compose exec n8n n8n export:workflow --backup --output=/files/backups/latest/ docker compose exec n8n n8n export:credentials --backup --output=/files/backups/latest/Exported credentials stay encrypted with your key, so the files are safe to store off-server. There is also a
--decryptedflag — never use it on exports you store anywhere except a vault, and never commit a decrypted export to Git. - The encryption key and the version. Store
N8N_ENCRYPTION_KEYin your password manager, and write down the pinned version (docker compose exec n8n n8n --version). A safe restore needs the same key and the same version.
Automate the pg_dump with a daily cron job and sync the file off the server — another host, or object storage. The same routine applies to any VPS service, and our automated VPS backups guide covers the cron-and-restore pattern in full. Then, once, actually restore onto a throwaway container and confirm your workflows come back. That one drill is worth more than a year of untested backup files.
One caveat for the future: n8n’s docs flag that these server CLI export commands are planned for eventual deprecation in favour of a newer n8n CLI tool built around .n8np package files, still in preview as of this writing. The commands above are today’s documented, stable path — nothing here disappears without notice.
Updating safely
Updates follow the sequence in n8n’s official docs. Back up first, then:
docker compose pull
docker compose down
docker compose up -d
docker compose down removes the containers but not the volumes, so your data survives. Two habits make updates boring instead of scary: check the release notes on GitHub before you bump the pinned version in the Compose file, and run the update when you have ten minutes to verify the editor and one active workflow afterwards. Never update right before a workflow you depend on is due to run.
7 mistakes that break self-hosted n8n
- Publishing port 5678 to the internet. The moment the editor is directly reachable, bots start probing the login page. Bind it to the internal network only and let the proxy be the door.
- Skipping
N8N_ENCRYPTION_KEY. Without it, n8n generates a key and stores it in the volume. Lose or recreate that volume and every saved credential is unreadable — permanently. - Running SQLite in production. SQLite is the default and it is fine for trying things out. n8n’s own docs say to use Postgres for an instance that must handle more than a handful of users or workflows running around the clock. SQLite also locks under concurrent writes, which is exactly what scheduled workflows do.
- A wrong
WEBHOOK_URL. Webhooks silently hand out unreachable URLs. Test a production webhook URL from outside your network on day one, not the day a customer integration depends on it. - Forgetting
N8N_PROXY_HOPS. Behind one proxy it should be1. Without it, n8n misreads client IPs and secure cookies misbehave — the symptom is usually a login loop or webhooks that work locally and fail in production. - Using
:latestand updating blind. n8n ships weekly. A floating tag plus an unattended restart is how a Monday-morning workflow breaks on a Sunday-night release. Pin the version, read the notes, update deliberately. - Backups you never tested. The
pg_dumpplus CLI export routine above takes five minutes to set up and one restore drill to trust. Until you have done the drill, assume the backup is broken.
When you should not self-host n8n
Self-hosting is the wrong call if nobody is willing to own the server. If updates, backups, and the occasional 2 a.m. “why did the workflow stop?” fall to no one, pay for n8n Cloud — Starter at €20 a month is cheap insurance against a dead automation nobody noticed. The same applies if you need the features that only ship on paid tiers: SSO and SAML, environments and Git version control, and the admin roles that come with the Business plan. And if your workflows are business-critical with no one on call, the hosted service’s uptime is worth more than the money you save.
But if you are a developer who already runs a VPS, the setup above costs you a small server bill and about half an hour — and in return you get unlimited executions, full control of your data, and an automation engine that never meters your curiosity.
Further Reading & References
- Install n8n using Docker Compose — official n8n docs
- Install n8n with Docker — official n8n docs
- n8n plans and pricing — n8n.io
- n8n hosting repository — official Docker Compose examples on GitHub
- n8n Backup and Update Tutorial: Restore Data and Upgrade Safely — CodingKit
- Self-host n8n on a VPS: Docker + HTTPS — SSD Nodes
- How to Self-Host n8n with Docker Compose and PostgreSQL (2026 Architecture Guide) — DEV Community
- How to Self-Host n8n on Docker in 5 Simple Steps — KDnuggets



