Deploying self-hosted n8n
This skill takes a fresh Linux VM (Ubuntu/Debian, root or sudo SSH) to a running,
HTTPS, production n8n via Docker Compose behind Caddy (automatic Let's Encrypt TLS).
It is for self-hosted n8n on Docker — not n8n Cloud, and not for building workflows
(that's the rest of this pack).
Two deployment modes. The architectures differ, so pick the mode before doing anything.
You drive this end-to-end over SSH: preflight → install Docker → lay down the project →
generate secrets → launch → verify TLS → hand off. The template files live in assets/;
the per-mode and security depth live in the reference files named below.
Rule 0 — choose the mode (ask the user)
Do not guess. Ask, then commit to one:
|
Single / regular |
Queue |
| Processes |
one n8n |
main + N workers |
| Extra services |
none (SQLite) |
Redis (queue) + Postgres (DB) |
| Executes workflows |
in the main process |
on workers, in parallel |
| Good for |
1 user, light/moderate load, simplest ops |
high volume, heavy/long executions, horizontal scale |
| Compose |
assets/docker-compose.single.yml |
assets/docker-compose.queue.yml |
| Deep dive |
SINGLE_MODE.md |
QUEUE_MODE.md |
If unsure, start single — it's the simplest correct thing and covers most needs. Moving
to queue later means swapping the compose file and migrating SQLite→Postgres, so if the user
already expects real volume, start queue.
Rule 1 — secret hygiene (non-negotiable)
A misstep here leaks client credentials. Be diligent:
- Generate every secret fresh, on the target box. Never copy an encryption key, DB
password, or
.env from another n8n instance into this one. See SECURITY.md for the
openssl commands.
- Secrets live only in
.env (mode 600), referenced by the compose as ${VAR}. Never
inline a secret into docker-compose.yml, the Caddyfile, or anything you commit.
- The
N8N_ENCRYPTION_KEY is sacred. It encrypts every stored credential. If it's lost
or changes, all saved credentials become undecryptable. Set it explicitly, and tell the
user to back it up off the box. Don't echo it into long-lived logs or chat history
beyond what's needed to hand it over.
- Never expose internal services. Only Caddy (80/443) is public. n8n (5678), Postgres
(5432), Redis (6379) stay on the private Docker network — the templates already omit their
host port mappings. Don't add them.
.env and Caddy's caddy_data volume (the issued certs + ACME account key) are not
artifacts to share. If you're working inside a git repo, confirm .env is git-ignored
before any commit.
Inputs to collect up front
- SSH target —
user@host and how you authenticate (key path or the user confirms the agent already has access). Root or a sudo user.
- Domain — the full hostname n8n will live at, e.g.
n8n.example.com (→ SUBDOMAIN=n8n, DOMAIN_NAME=example.com). The user must control its DNS.
- TLS email — for Let's Encrypt (
SSL_EMAIL).
- Timezone — IANA name for Schedule/Cron nodes (e.g.
Europe/Warsaw), else Etc/UTC.
- Mode — single or queue (Rule 0). Queue → confirm the box has enough RAM (rough floor ~4 GB; each worker wants ~1–2 GB).
- Optional modules — some features (currently Agents) are backend modules that stay off
unless listed in
N8N_ENABLED_MODULES. Ask only if the user brings one up; if they do, read
the modules section of QUEUE_MODE.md before enabling it, because in queue mode it has to
reach the workers as well.
The deploy flow
Work through these in order. SINGLE_MODE.md / QUEUE_MODE.md give the mode-specific command
detail; SECURITY.md covers secret generation and hardening; DAY2.md covers update/backup/restore.
1. Preflight (the cheapest failure is the one you catch here)
- SSH in; confirm the OS is Debian/Ubuntu-like (
. /etc/os-release).
- DNS must already point at the box. Compare the box's public IP (
curl -s ifconfig.me)
with dig +short <fqdn> (run it from the box AND ideally your laptop). If they don't match,
stop — Caddy's ACME challenge will fail. Have the user create the A record, wait for it
to propagate, then continue.
- Ports 80 and 443 must be reachable from the internet. Check the host firewall AND any
cloud security group / network firewall (Hetzner Cloud, AWS SG, etc.) — these are outside
the box and a common silent blocker.
2. Install Docker (if absent)
- Check
docker --version and docker compose version. If missing, install Docker Engine +
the Compose plugin (Docker's official get.docker.com script on Ubuntu/Debian is fine).
Re-check docker compose version before proceeding.
3. Lay down the project
- Pick
DATA_FOLDER — an absolute path, e.g. /opt/n8n. The DATA_FOLDER value in .env
must equal this exact directory (the compose mounts ${DATA_FOLDER}/caddy_config/Caddyfile,
and init-data.sh is mounted via a relative ./ path), so always run docker compose from
here. Create it, plus caddy_config/ and local_files/ inside.
- Get the template files onto the box. They live in this skill's
assets/ on your machine,
not on the server — transfer each one. Either scp them up, or (no local copy needed) write
each file's contents over SSH, e.g.
ssh <target> 'cat > <DATA_FOLDER>/docker-compose.yml' < assets/docker-compose.single.yml.
Land them with these exact names:
- the chosen compose →
<DATA_FOLDER>/docker-compose.yml (rename it to exactly this)
Caddyfile → <DATA_FOLDER>/caddy_config/Caddyfile
- queue only:
init-data.sh → <DATA_FOLDER>/init-data.sh, then chmod +x it
- the matching
.env.*.example → <DATA_FOLDER>/.env
4. Fill .env + generate secrets
- Set
DATA_FOLDER, DOMAIN_NAME, SUBDOMAIN, SSL_EMAIL, GENERIC_TIMEZONE.
- Generate each secret on the box with
openssl (SECURITY.md has the commands) and write
it into .env, replacing the matching REPLACE_WITH_… placeholder: N8N_ENCRYPTION_KEY;
queue also POSTGRES_PASSWORD + POSTGRES_NON_ROOT_PASSWORD.
- Before launching, confirm none are left unset:
grep REPLACE_WITH_ .env must return nothing
— a leftover placeholder becomes the literal password and Postgres/n8n fail to connect.
chmod 600 .env. Record the encryption key so the user can back it up off-box.
5. Firewall
ufw: allow OpenSSH + 80 + 443, then enable. Do not open 5678/5432/6379.
6. Launch
cd <DATA_FOLDER> && docker compose up -d.
- Queue mode brings up Redis + Postgres + main + workers (workers via
replicas). To add
capacity: docker compose up -d --scale n8n-worker=N.
7. Verify (don't declare success without this)
docker compose ps — every service Up/healthy (queue: postgres & redis healthy first).
- n8n itself up (internal):
docker compose exec n8n wget -qO- http://localhost:5678/healthz
→ {"status":"ok"}. This separates "n8n is running" from "TLS isn't ready yet."
- Cert issued:
docker compose logs caddy | grep -i 'certificate obtained'. First-boot ACME
can take a minute or two; until it finishes, a public https:// request fails TLS — that means
the cert is still pending, not that n8n is down.
- Public reachability (with retry):
curl -fsS --retry 5 --retry-delay 10 https://<fqdn>/healthz
→ {"status":"ok"}. (/healthz only proves the process is reachable; /healthz/readiness
additionally confirms the DB is connected and migrated — use it when debugging a boot loop.)
- Queue mode — main and workers must agree. Diff their environments:
diff <(docker compose exec -T n8n env | sort) <(docker compose exec -T --index 1 n8n-worker env | sort).
Only the public-URL/proxy vars should differ. Anything else means a behavioural setting reached
the main but not the workers — and workers are what execute workflows, so it fails at runtime
in one node rather than at boot. QUEUE_MODE.md explains the rule.
- Open
https://<fqdn> → the owner setup screen. Whoever completes that signup form first
claims the instance — an exposed un-owned instance is a race, so create the owner account
immediately, before sharing the URL. Enable 2FA. (Automated deploys can pre-provision the
owner via env vars instead — see the owner row in SECURITY.md.)
8. Hand off
- Give the user: the URL, where the project lives, the encryption key to store safely, and the
Day-2 basics (update / backup / restore) from
DAY2.md.
What NOT to do
- Don't skip the DNS/ports preflight. A wrong A record or a closed cloud firewall is the
#1 reason Caddy can't get a cert and n8n looks "broken."
- Don't publish 5678/5432/6379 to the host. Caddy reaches n8n over the private network.
- Don't reuse another instance's encryption key or
.env. Fresh secrets per box.
- Don't run queue mode on SQLite. Queue requires Postgres (the template already wires it).
- Don't put secrets in
docker-compose.yml or the Caddyfile. .env only.
- Don't add a behavioural env var to the main only (queue mode). Modules, DB, queue,
binary-data and encryption settings belong in the shared
x-n8n-env anchor so workers get
them too; only the public-URL/proxy vars are main-only. See QUEUE_MODE.md.
- Don't use
:latest blindly. Pin N8N_IMAGE_TAG; update deliberately (DAY2.md).
Reference files
SINGLE_MODE.md — single-instance specifics, SQLite vs Postgres, when to graduate to queue.
QUEUE_MODE.md — queue architecture, workers/concurrency/scaling, shared encryption key, the main-vs-worker env-parity rule, optional backend modules (N8N_ENABLED_MODULES, e.g. Agents), binary data (database mode — filesystem is unsupported in queue mode; S3/Azure = Enterprise), webhook processors, multi-main licensing.
SECURITY.md — generating secrets, the encryption-key rules, the full hardening checklist (telemetry off, env-access block, public API, firewall, secure cookies).
CREDENTIAL_OVERWRITES.md — managed OAuth: register one OAuth app instance-wide so users
never see a client ID/secret ("Sign in with Google" on self-hosted). The endpoint-vs-env choice,
the mandatory endpoint auth token, parent-type inheritance, persistence and worker reload.
DAY2.md — changing a setting (env var) safely, updating the image, backing up (encryption key + volume + Postgres), and restoring.
assets/ — the templates: docker-compose.single.yml, docker-compose.queue.yml, Caddyfile, .env.single.example, .env.queue.example, init-data.sh.
Authoritative upstream reference: the official hosting docs live at
https://docs.n8n.io/deploy/host-n8n (restructured mid-2026 from the old /hosting/ paths —
prefer these URLs). The env-var reference index is at
https://docs.n8n.io/deploy/host-n8n/configure-n8n/basic-configuration/use-environment-variables.
When this skill and the live docs disagree, trust the docs and tell the user.
1---2name: n8n-self-hosting3description: Deploy a production self-hosted n8n end-to-end to a fresh Linux VM over SSH, using Docker Compose behind a Caddy reverse proxy with automatic HTTPS. Use whenever the user wants to self-host, install, set up, provision, or deploy n8n on their own server/VPS/box (Hetzner, DigitalOcean, AWS EC2, bare metal, etc.) — in either single/regular mode or queue mode with workers — or to update, back up, restore, or harden such an instance. This is for SELF-HOSTED n8n (Docker), not n8n Cloud and not building workflows. The skill makes the agent ask single-vs-queue first, collect the domain/SSH/timezone inputs, generate fresh secrets on the box, and bring the stack up with TLS. Trigger on "deploy n8n", "self-host n8n", "install n8n on my server", "n8n docker compose", "n8n queue mode / workers / scaling", "n8n reverse proxy / SSL", "back up / update my n8n", or "we don't want to give every user the OAuth client secret" / "enable the Sign in with Google button" (credential overwrites).4---5
6# Deploying self-hosted n8n
7
8This skill takes a **fresh Linux VM** (Ubuntu/Debian, root or sudo SSH) to a **running,
9HTTPS, production n8n** via Docker Compose behind **Caddy** (automatic Let's Encrypt TLS).
10It is for **self-hosted n8n on Docker** — not n8n Cloud, and not for building workflows
11(that's the rest of this pack).
12
13Two deployment modes. The architectures differ, so **pick the mode before doing anything**.
14
15You drive this end-to-end over SSH: preflight → install Docker → lay down the project →
16generate secrets → launch → verify TLS → hand off. The template files live in `assets/`;
17the per-mode and security depth live in the reference files named below.
18
19## Rule 0 — choose the mode (ask the user)
20
21Do not guess. Ask, then commit to one:
22
23| | **Single / regular** | **Queue** |
24|---|---|---|
25| Processes | one n8n | main + N workers |
26| Extra services | none (SQLite) | Redis (queue) + Postgres (DB) |
27| Executes workflows | in the main process | on workers, in parallel |
28| Good for | 1 user, light/moderate load, simplest ops | high volume, heavy/long executions, horizontal scale |
29| Compose | `assets/docker-compose.single.yml` | `assets/docker-compose.queue.yml` |
30| Deep dive | **`SINGLE_MODE.md`** | **`QUEUE_MODE.md`** |
31
32If unsure, start **single** — it's the simplest correct thing and covers most needs. Moving
33to queue later means swapping the compose file and migrating SQLite→Postgres, so if the user
34already expects real volume, start **queue**.
35
36## Rule 1 — secret hygiene (non-negotiable)
37
38A misstep here leaks client credentials. Be diligent:
39
401. **Generate every secret fresh, on the target box.** Never copy an encryption key, DB
41 password, or `.env` from another n8n instance into this one. See `SECURITY.md` for the
42 `openssl` commands.
432. **Secrets live only in `.env`** (mode 600), referenced by the compose as `${VAR}`. Never
44 inline a secret into `docker-compose.yml`, the Caddyfile, or anything you commit.
453. **The `N8N_ENCRYPTION_KEY` is sacred.** It encrypts every stored credential. If it's lost
46 or changes, all saved credentials become undecryptable. Set it explicitly, and tell the
47 user to back it up **off the box**. Don't echo it into long-lived logs or chat history
48 beyond what's needed to hand it over.
494. **Never expose internal services.** Only Caddy (80/443) is public. n8n (5678), Postgres
50 (5432), Redis (6379) stay on the private Docker network — the templates already omit their
51 host port mappings. Don't add them.
525. **`.env` and Caddy's `caddy_data` volume (the issued certs + ACME account key) are not
53 artifacts to share.** If you're working inside a git repo, confirm `.env` is git-ignored
54 before any commit.
55
56## Inputs to collect up front
57
58- **SSH target** — `user@host` and how you authenticate (key path or the user confirms the agent already has access). Root or a sudo user.
59- **Domain** — the full hostname n8n will live at, e.g. `n8n.example.com` (→ `SUBDOMAIN=n8n`, `DOMAIN_NAME=example.com`). The user must control its DNS.
60- **TLS email** — for Let's Encrypt (`SSL_EMAIL`).
61- **Timezone** — IANA name for Schedule/Cron nodes (e.g. `Europe/Warsaw`), else `Etc/UTC`.
62- **Mode** — single or queue (Rule 0). Queue → confirm the box has enough RAM (rough floor ~4 GB; each worker wants ~1–2 GB).
63- **Optional modules** — some features (currently **Agents**) are backend modules that stay off
64 unless listed in `N8N_ENABLED_MODULES`. Ask only if the user brings one up; if they do, read
65 the modules section of `QUEUE_MODE.md` before enabling it, because in queue mode it has to
66 reach the workers as well.
67
68## The deploy flow
69
70Work through these in order. `SINGLE_MODE.md` / `QUEUE_MODE.md` give the mode-specific command
71detail; `SECURITY.md` covers secret generation and hardening; `DAY2.md` covers update/backup/restore.
72
73### 1. Preflight (the cheapest failure is the one you catch here)
74- SSH in; confirm the OS is Debian/Ubuntu-like (`. /etc/os-release`).
75- **DNS must already point at the box.** Compare the box's public IP (`curl -s ifconfig.me`)
76 with `dig +short <fqdn>` (run it from the box AND ideally your laptop). If they don't match,
77 **stop** — Caddy's ACME challenge will fail. Have the user create the A record, wait for it
78 to propagate, then continue.
79- Ports **80 and 443** must be reachable from the internet. Check the host firewall AND any
80 cloud security group / network firewall (Hetzner Cloud, AWS SG, etc.) — these are outside
81 the box and a common silent blocker.
82
83### 2. Install Docker (if absent)
84- Check `docker --version` and `docker compose version`. If missing, install Docker Engine +
85 the Compose plugin (Docker's official `get.docker.com` script on Ubuntu/Debian is fine).
86 Re-check `docker compose version` before proceeding.
87
88### 3. Lay down the project
89- Pick `DATA_FOLDER` — an **absolute path**, e.g. `/opt/n8n`. The `DATA_FOLDER` value in `.env`
90 **must equal this exact directory** (the compose mounts `${DATA_FOLDER}/caddy_config/Caddyfile`,
91 and `init-data.sh` is mounted via a relative `./` path), so always run `docker compose` from
92 here. Create it, plus `caddy_config/` and `local_files/` inside.
93- **Get the template files onto the box.** They live in this skill's `assets/` on *your* machine,
94 not on the server — transfer each one. Either `scp` them up, or (no local copy needed) write
95 each file's contents over SSH, e.g.
96 `ssh <target> 'cat > <DATA_FOLDER>/docker-compose.yml' < assets/docker-compose.single.yml`.
97 Land them with these exact names:
98 - the chosen compose → `<DATA_FOLDER>/docker-compose.yml` (rename it to exactly this)
99 - `Caddyfile` → `<DATA_FOLDER>/caddy_config/Caddyfile`
100 - **queue only:** `init-data.sh` → `<DATA_FOLDER>/init-data.sh`, then `chmod +x` it
101 - the matching `.env.*.example` → `<DATA_FOLDER>/.env`
102
103### 4. Fill `.env` + generate secrets
104- Set `DATA_FOLDER`, `DOMAIN_NAME`, `SUBDOMAIN`, `SSL_EMAIL`, `GENERIC_TIMEZONE`.
105- Generate each secret **on the box** with `openssl` (`SECURITY.md` has the commands) and **write
106 it into `.env`, replacing the matching `REPLACE_WITH_…` placeholder**: `N8N_ENCRYPTION_KEY`;
107 queue also `POSTGRES_PASSWORD` + `POSTGRES_NON_ROOT_PASSWORD`.
108- **Before launching, confirm none are left unset:** `grep REPLACE_WITH_ .env` must return nothing
109 — a leftover placeholder becomes the literal password and Postgres/n8n fail to connect.
110- `chmod 600 .env`. Record the encryption key so the user can back it up off-box.
111
112### 5. Firewall
113- `ufw`: allow OpenSSH + 80 + 443, then enable. Do **not** open 5678/5432/6379.
114
115### 6. Launch
116- `cd <DATA_FOLDER> && docker compose up -d`.
117- Queue mode brings up Redis + Postgres + main + workers (workers via `replicas`). To add
118 capacity: `docker compose up -d --scale n8n-worker=N`.
119
120### 7. Verify (don't declare success without this)
121- `docker compose ps` — every service `Up`/healthy (queue: postgres & redis `healthy` first).
122- **n8n itself up (internal):** `docker compose exec n8n wget -qO- http://localhost:5678/healthz`
123 → `{"status":"ok"}`. This separates "n8n is running" from "TLS isn't ready yet."
124- **Cert issued:** `docker compose logs caddy | grep -i 'certificate obtained'`. First-boot ACME
125 can take a minute or two; until it finishes, a public `https://` request fails TLS — that means
126 the cert is still pending, **not** that n8n is down.
127- **Public reachability (with retry):** `curl -fsS --retry 5 --retry-delay 10 https://<fqdn>/healthz`
128 → `{"status":"ok"}`. (`/healthz` only proves the process is reachable; `/healthz/readiness`
129 additionally confirms the DB is connected and migrated — use it when debugging a boot loop.)
130- **Queue mode — main and workers must agree.** Diff their environments:
131 `diff <(docker compose exec -T n8n env | sort) <(docker compose exec -T --index 1 n8n-worker env | sort)`.
132 Only the public-URL/proxy vars should differ. Anything else means a behavioural setting reached
133 the main but not the workers — and workers are what execute workflows, so it fails at runtime
134 in one node rather than at boot. `QUEUE_MODE.md` explains the rule.
135- Open `https://<fqdn>` → the **owner setup** screen. **Whoever completes that signup form first
136 claims the instance** — an exposed un-owned instance is a race, so create the owner account
137 immediately, before sharing the URL. Enable 2FA. (Automated deploys can pre-provision the
138 owner via env vars instead — see the owner row in `SECURITY.md`.)
139
140### 8. Hand off
141- Give the user: the URL, where the project lives, the encryption key to store safely, and the
142 Day-2 basics (update / backup / restore) from **`DAY2.md`**.
143
144## What NOT to do
145
146- **Don't skip the DNS/ports preflight.** A wrong A record or a closed cloud firewall is the
147 #1 reason Caddy can't get a cert and n8n looks "broken."
148- **Don't publish 5678/5432/6379** to the host. Caddy reaches n8n over the private network.
149- **Don't reuse another instance's encryption key or `.env`.** Fresh secrets per box.
150- **Don't run queue mode on SQLite.** Queue requires Postgres (the template already wires it).
151- **Don't put secrets in `docker-compose.yml` or the Caddyfile.** `.env` only.
152- **Don't add a behavioural env var to the main only (queue mode).** Modules, DB, queue,
153 binary-data and encryption settings belong in the shared `x-n8n-env` anchor so workers get
154 them too; only the public-URL/proxy vars are main-only. See `QUEUE_MODE.md`.
155- **Don't use `:latest` blindly.** Pin `N8N_IMAGE_TAG`; update deliberately (`DAY2.md`).
156
157## Reference files
158
159- **`SINGLE_MODE.md`** — single-instance specifics, SQLite vs Postgres, when to graduate to queue.
160- **`QUEUE_MODE.md`** — queue architecture, workers/concurrency/scaling, shared encryption key, the main-vs-worker **env-parity rule**, optional backend modules (`N8N_ENABLED_MODULES`, e.g. Agents), binary data (`database` mode — filesystem is unsupported in queue mode; S3/Azure = Enterprise), webhook processors, multi-main licensing.
161- **`SECURITY.md`** — generating secrets, the encryption-key rules, the full hardening checklist (telemetry off, env-access block, public API, firewall, secure cookies).
162- **`CREDENTIAL_OVERWRITES.md`** — managed OAuth: register one OAuth app instance-wide so users
163 never see a client ID/secret ("Sign in with Google" on self-hosted). The endpoint-vs-env choice,
164 the **mandatory** endpoint auth token, parent-type inheritance, persistence and worker reload.
165- **`DAY2.md`** — changing a setting (env var) safely, updating the image, backing up (encryption key + volume + Postgres), and restoring.
166- **`assets/`** — the templates: `docker-compose.single.yml`, `docker-compose.queue.yml`, `Caddyfile`, `.env.single.example`, `.env.queue.example`, `init-data.sh`.
167
168Authoritative upstream reference: the official hosting docs live at
169<https://docs.n8n.io/deploy/host-n8n> (restructured mid-2026 from the old `/hosting/` paths —
170prefer these URLs). The env-var reference index is at
171<https://docs.n8n.io/deploy/host-n8n/configure-n8n/basic-configuration/use-environment-variables>.
172When this skill and the live docs disagree, trust the docs and tell the user.