N8n self hosting

From WilkoMarketing/antigravity-n8n-skills · View interactive version

N8n self hosting is an AI agent skill from the GitHub repository WilkoMarketing/antigravity-n8n-skills. 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, provision, or deploy n8n on their own server/VPS (Hetzner, DigitalOcean, AWS EC2, bare metal) — sing

How to use this skill

Skill file

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:

  1. 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.

  1. 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.

  1. 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.

  1. 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.

  1. **.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

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.

will anyone besides you edit workflows?"* A yes to either means task runners in **external

mode**: a n8nio/runners sidecar (one per worker in queue mode). The stock n8nio/n8n image has

no Python 3, so in the default internal mode every Python Code node fails with `Python runner

unavailable: Python 3 is missing from this system. Read TASK_RUNNERS.md` before 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)

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.

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)

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

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.

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 compose now (TASK_RUNNERS.md has the snippet for each mode). Generate

N8N_RUNNERS_AUTH_TOKEN in step 4 with the other secrets.

4. Fill `.env` + generate secrets

it into .env, replacing the matching REPLACE_WITH_… placeholder**: N8N_ENCRYPTION_KEY;

queue also POSTGRES_PASSWORD + POSTGRES_NON_ROOT_PASSWORD.

— a leftover placeholder becomes the literal password and Postgres/n8n fail to connect.

5. Firewall

6. Launch

capacity: docker compose up -d --scale n8n-worker=N.

7. Verify (don't declare success without this)

→ {"status":"ok"}. This separates "n8n is running" from "TLS isn't ready yet."

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.

→ {"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.)

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.

launcher-javascript and launcher-python (queue: check every worker). Then smoke-test a

Python Code node (TASK_RUNNERS.md → Verify).

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

Day-2 basics (update / backup / restore) from DAY2.md.

What NOT to do

#1 reason Caddy can't get a cert and n8n looks "broken."

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.

n8nio/runners sidecar, on exactly the n8n version, with imports allowlisted in the launcher

config. By default even import json is rejected. See TASK_RUNNERS.md.

worker. Add worker + runner pairs instead (TASK_RUNNERS.md).

Reference files

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.

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.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.