N8n Self Hosting
Romuald CzlonkowskiCommunityCreated by Romuald Czlonkowski
- Skill
- Workflow
- Automation and integrations
- MIT
- Low risk
- Has scripts
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides a structured procedure for deploying n8n on a fresh Linux VM via SSH. It automates the setup of Docker, Caddy for automatic HTTPS, and the necessary Docker Compose configuration. The skill supports two deployment architectures: a single-instance mode for simpler setups and a queue-based mode for horizontal scaling. It includes guidance on secret management, firewall configuration, and the integration of external task runners for Python Code nodes, ensuring a secure and functional self-hosted environment.
What it does
- Deploys n8n using Docker Compose and a Caddy reverse proxy.
- Configures automatic HTTPS via Let's Encrypt.
- Supports both single-instance and queue-based deployment modes.
- Manages fresh secret generation and environment variable security.
- Integrates external task runners for Python Code node execution.
- Provides procedures for updates, backups, and instance hardening.
When to use it
- When you need to install n8n on your own infrastructure or VPS.
- When you require a specific deployment mode like queue mode for scaling.
- When you need to enable Python Code nodes using external task runners.
- When you need to update, back up, or restore an existing self-hosted n8n instance.
Advantages
- Ensures consistent deployment through standardized templates.
- Automates complex tasks like TLS certificate management.
- Promotes secure practices by enforcing fresh secret generation.
- Provides clear paths for scaling from single to queue-based architectures.
Usage examples
- “Deploy n8n on my new Ubuntu server.”
- The agent will initiate the preflight check, ask for your deployment mode preference, and guide you through the installation of Docker and the n8n stack.
- “I need to set up n8n in queue mode with workers.”
- The agent will collect the necessary domain and SSH details, then configure the stack with Redis and Postgres to support horizontal scaling.
- “How do I enable Python Code nodes on my self-hosted n8n?”
- The agent will guide you through adding the n8nio/runners sidecar to your existing Docker Compose configuration.
- “Help me back up my self-hosted n8n instance.”
- The agent will provide the steps to safely export your encryption key, database, and volume data.
Install
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/czlonkowski/n8n-self-hosting/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip n8n-self-hosting.zip -d .agents/skills
Documentation by Romuald Czlonkowski
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
.envfrom another n8n instance into this one. SeeSECURITY.mdfor theopensslcommands.Secrets live only in
.env(mode 600), referenced by the compose as${VAR}. Never inline a secret intodocker-compose.yml, the Caddyfile, or anything you commit.The
N8N_ENCRYPTION_KEYis 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.
.envand Caddy'scaddy_datavolume (the issued certs + ACME account key) are not artifacts to share. If you're working inside a git repo, confirm.envis git-ignored before any commit.
Inputs to collect up front
SSH target —
user@hostand 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), elseEtc/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 ofQUEUE_MODE.mdbefore enabling it, because in queue mode it has to reach the workers as well.Python Code nodes / who edits workflows — ask "Will workflows use Python Code nodes, or will anyone besides you edit workflows?" A yes to either means task runners in external mode: a
n8nio/runnerssidecar (one per worker in queue mode). The stockn8nio/n8nimage has no Python 3, so in the default internal mode every Python Code node fails withPython runner unavailable: Python 3 is missing from this system. ReadTASK_RUNNERS.mdbefore step 3.
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) withdig +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 --versionanddocker compose version. If missing, install Docker Engine + the Compose plugin (Docker's officialget.docker.comscript on Ubuntu/Debian is fine). Re-checkdocker compose versionbefore proceeding.
3. Lay down the project
Pick
DATA_FOLDER— an absolute path, e.g./opt/n8n. TheDATA_FOLDERvalue in.envmust equal this exact directory (the compose mounts${DATA_FOLDER}/caddy_config/Caddyfile, andinit-data.shis mounted via a relative./path), so always rundocker composefrom here. Create it, pluscaddy_config/andlocal_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. Eitherscpthem 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/Caddyfilequeue only:
init-data.sh→<DATA_FOLDER>/init-data.sh, thenchmod +xitthe matching
.env.*.example→<DATA_FOLDER>/.env
External task runners (Python): add the runner env vars and the
task-runnerssidecar to the compose now (TASK_RUNNERS.mdhas the snippet for each mode). GenerateN8N_RUNNERS_AUTH_TOKENin step 4 with the other secrets.
4. Fill .env + generate secrets
Set
DATA_FOLDER,DOMAIN_NAME,SUBDOMAIN,SSL_EMAIL,GENERIC_TIMEZONE.Generate each secret on the box with
openssl(SECURITY.mdhas the commands) and write it into.env, replacing the matchingREPLACE_WITH_…placeholder:N8N_ENCRYPTION_KEY; queue alsoPOSTGRES_PASSWORD+POSTGRES_NON_ROOT_PASSWORD.Before launching, confirm none are left unset:
grep REPLACE_WITH_ .envmust 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 serviceUp/healthy (queue: postgres & redishealthyfirst).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 publichttps://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"}. (/healthzonly proves the process is reachable;/healthz/readinessadditionally 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.mdexplains the rule.External task runners:
docker compose logs n8n | grep 'Registered runner'must show bothlauncher-javascriptandlauncher-python(queue: check every worker). Then smoke-test a Python Code node (TASK_RUNNERS.md→ Verify).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 inSECURITY.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.ymlor the Caddyfile..envonly.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-envanchor so workers get them too; only the public-URL/proxy vars are main-only. SeeQUEUE_MODE.md.Don't use
:latestblindly. PinN8N_IMAGE_TAG; update deliberately (DAY2.md).Don't promise Python Code nodes on the stock image in internal mode. They need the
n8nio/runnerssidecar, on exactly the n8n version, with imports allowlisted in the launcher config. By default evenimport jsonis rejected. SeeTASK_RUNNERS.md.Don't
--scalequeue workers once runners are external. A sidecar serves exactly one worker. Add worker + runner pairs instead (TASK_RUNNERS.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 (databasemode — 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.TASK_RUNNERS.md— task runners in external mode: why Python Code nodes need then8nio/runnerssidecar, the compose snippet for single mode and the one-sidecar-per-worker pattern for queue mode, allowlisting Python/JS modules via/etc/n8n-task-runners.json, the builtin deny list, verification, failure signatures, and upgrading n8n and the runners together.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.
Files
- ATTRIBUTION.mdAdded by AutoGineer889 B
- CREDENTIAL_OVERWRITES.md7.9 KiB
- DAY2.md8.6 KiB
- LICENSELicence file added by AutoGineer1.1 KiB
- QUEUE_MODE.md10.3 KiB
- README.md5.2 KiB
- SECURITY.md8.4 KiB
- SINGLE_MODE.md3.6 KiB
- SKILL.md13.7 KiB
- TASK_RUNNERS.md9.5 KiB
- assets/.env.queue.example1.8 KiB
- assets/.env.single.example1.4 KiB
- assets/Caddyfile1.1 KiB
- assets/docker-compose.queue.yml6.7 KiB
- assets/docker-compose.single.yml3.0 KiB
- assets/init-data.shScript924 B
DAY2.md
Day-2: update, back up, restore
Operating the instance after it's live. All commands run from <DATA_FOLDER> on the box.
Update the n8n image
n8n ships breaking changes between majors — pin a version in .env (N8N_IMAGE_TAG) and bump
it deliberately rather than chasing :latest.
cd <DATA_FOLDER>
# (optional) bump N8N_IMAGE_TAG in .env to a specific version first
docker compose pull
docker compose up -d # recreates only changed services; volumes/data persist
docker compose exec n8n n8n --version(The docs' own sequence inserts docker compose down between pull and up -d; skipping it as
above avoids the full-stack teardown and is equally safe for data — either works.)
Queue mode:
pull+up -dupdates main and workers together — keep them on the same version (a mixed-version cluster misbehaves).External task runners: the
n8nio/runnerssidecar(s) must move to exactly the same version. Drive both images fromN8N_IMAGE_TAGso one bump updates both. If you mounted a customn8n-task-runners.json, diff it against the new image's default first (docker run --rm --entrypoint cat n8nio/runners:<new-tag> /etc/n8n-task-runners.json). A stale copy can silently drop env vars that a newer launcher passes to the runners. SeeTASK_RUNNERS.md.On restart, containers get
N8N_GRACEFUL_SHUTDOWN_TIMEOUT(default 30 s) to finish in-flight executions before being killed — raise it if long-running workflows keep getting cut off mid-update. (The oldQUEUE_WORKER_TIMEOUTis deprecated in favor of this.)Rollback is only half-safe. Pinning the previous
N8N_IMAGE_TAGworks if no DB migration ran during the update. n8n auto-runs migrations on boot and they are forward-only — the docs document no downgrade path — so once the new version has booted against the DB, a clean rollback means old image tag plus restoring the pre-update DB backup. This is why the backup below comes before the update, not after it breaks.Update deliberately but regularly (docs suggest at least monthly, so you never jump many versions at once) and read the release notes for breaking changes before every update, not just majors. For instances a business depends on, docs recommend trying the update on a staging copy first. Official update guide: https://docs.n8n.io/deploy/host-n8n/keep-n8n-running/update-n8n.
Change a setting (env var)
The most common day-2 operation, and the one with the most ways to go subtly wrong.
cd <DATA_FOLDER>
# edit .env (values) or docker-compose.yml (which vars exist)
docker compose config -q # catch YAML/interpolation errors before restarting
docker compose up -d --no-deps n8n # recreate just this service--no-depskeeps the blast radius small. Without it Compose may also touch the services this one depends on. Restart only what actually needs the new value.Don't restart via a wrapper script that pulls. A
run.sh/update.shthat doesdocker compose pull && up -dturns "apply a setting" into "apply a setting and upgrade n8n" — you then debug two changes at once, and the upgrade may have run a forward-only DB migration you didn't plan for. Use plainup -dfor env changes; use the update recipe above when you actually mean to update.Take a copy of the compose file first (
cp docker-compose.yml docker-compose.yml.bak-$(date +%F)) so reverting is onecprather than a reconstruction from memory.Queue mode: decide whether the var is behavioural. If it changes how n8n behaves rather than what public URL it serves, it belongs in the
x-n8n-envanchor and the workers need recreating too (docker compose up -d --no-deps n8n n8n-worker). Re-run the parity diff fromQUEUE_MODE.mdafterwards — that check is what turns "I think I set it" into "it's set everywhere it needs to be".Never restart to apply a changed
N8N_ENCRYPTION_KEY. That doesn't re-key anything; it makes every stored credential undecryptable. The key is set once, at first boot, forever.
Back up — what actually matters
Two things, and they're only useful together:
The
N8N_ENCRYPTION_KEY— it's in.env(and then8n_data/n8n_storagevolume at~/.n8n/config). Store it off-box. A DB backup without this key is undecryptable.The data:
Single (SQLite): the
n8n_datavolume (holds the SQLite DB, the key, and filesystem binary data).Queue (Postgres): a
pg_dumpof the database. With the template'sN8N_DEFAULT_BINARY_DATA_MODE=database, binary data is inside Postgres, so the dump covers it — then8n_storagetar below is belt-and-braces for~/.n8nitself (config, including any auto-generated key).
Single (SQLite) — snapshot the volume
docker run --rm \
-v n8n_data:/data -v "$PWD":/backup alpine \
tar czf /backup/n8n_data-$(date +%F).tar.gz -C /data .
# also copy .env (it holds the encryption key) somewhere safe & privateQueue (Postgres) — dump the DB
# Single-quote the inner command so $POSTGRES_USER/$POSTGRES_DB expand INSIDE the
# postgres container (where they're set), not in your host shell (where they aren't).
docker compose exec -T postgres \
sh -c 'pg_dump -U "$POSTGRES_USER" -d "$POSTGRES_DB"' \
| gzip > n8n-db-$(date +%F).sql.gz
# optional but cheap — the ~/.n8n volume (config; name matches the compose `name:`):
docker run --rm -v n8n_storage:/data -v "$PWD":/backup alpine \
tar czf /backup/n8n_storage-$(date +%F).tar.gz -C /data .
# and back up .env (encryption key) off-boxSchedule these (cron) and copy the artifacts off the machine. Test a restore at least once.
Alternative: CLI export (portable, human-readable)
For workflow-level backups (e.g. before risky edits) the CLI has a purpose-built flag:
docker compose exec -u node n8n n8n export:workflow --backup --output=/home/node/.n8n/backup/Credentials export encrypted by default (n8n export:credentials --all) and need the same
N8N_ENCRYPTION_KEY to re-import; --decrypted writes plaintext secrets — treat such a
file as a live credential dump. CLI reference:
https://docs.n8n.io/deploy/host-n8n/configure-n8n/use-the-command-line.
Restore
The golden rule: restore the data with the original N8N_ENCRYPTION_KEY in place, or saved
credentials won't decrypt. So put the backed-up key into .env before bringing n8n up.
Single (SQLite)
# fresh box: lay down the project + .env (with the ORIGINAL encryption key), do NOT start n8n yet
docker volume create n8n_data
docker run --rm -v n8n_data:/data -v "$PWD":/backup alpine \
sh -c 'cd /data && tar xzf /backup/n8n_data-YYYY-MM-DD.tar.gz'
docker compose up -dQueue (Postgres)
# bring up just the DB first so it's ready to receive the dump
docker compose up -d postgres
gunzip -c n8n-db-YYYY-MM-DD.sql.gz | \
docker compose exec -T postgres sh -c 'psql -U "$POSTGRES_USER" -d "$POSTGRES_DB"'
# restore the binary volume if you backed it up, then:
docker compose up -dRoutine checks
docker compose ps # health
docker compose logs -f n8n # main logs
docker system df # disk used by images/volumes
df -h # host disk (watch execution data + binary growth)If disk creeps up, tighten execution pruning (EXECUTIONS_DATA_MAX_AGE /
EXECUTIONS_DATA_PRUNE_MAX_COUNT; defaults 336 h / 10 000 — the templates set them explicitly).
In single mode also confirm N8N_DEFAULT_BINARY_DATA_MODE=filesystem so run payloads aren't
bloating SQLite; in queue mode binary data intentionally lives in Postgres, so pruning is what
bounds it.
Going further (all optional):
Log tuning —
N8N_LOG_LEVEL(infodefault;debugwhen diagnosing) andN8N_LOG_OUTPUT=consolefit Docker; file output + rotation vars exist: https://docs.n8n.io/deploy/host-n8n/keep-n8n-running/set-up-logging.Prometheus —
N8N_METRICS=trueexposes/metricsunauthenticated; since Caddy proxies everything, that would be public — keep it off, or block/metricsin the Caddyfile first: https://docs.n8n.io/deploy/host-n8n/configure-n8n/basic-configuration/configuration-examples/enable-prometheus-metrics.Health/monitoring endpoints —
/healthz(process up) vs/healthz/readiness(DB ready): https://docs.n8n.io/deploy/host-n8n/keep-n8n-running/monitor-n8n.Periodic security audit —
docker compose exec -u node n8n n8n audit(or then8n_audit_instanceMCP tool from the n8n-mcp pack): https://docs.n8n.io/deploy/host-n8n/configure-n8n/security/run-security-audits.
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs network access, Needs Python, Needs Node.js
Security
What our scanner noticed· Low risk
- Instructions that use the network
- Scripts that your agent may run
This skill includes scripts that your agent may run. Read them before you use it.
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- Romuald Czlonkowski
- Publisher
- Romuald Czlonkowski (Community)
- Source
- czlonkowski/n8n-skills · skills/n8n-self-hosting · commit e037563
- Licence
- MIT License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by Romuald Czlonkowski.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download n8n-self-hosting.zip