{"slug": "self-host-n8n-on-a-vps-with-docker-and-caddy-and-claim-the-owner-account-before", "title": "Self-host n8n on a VPS with Docker and Caddy (and claim the owner account before anyone else does)", "summary": "A developer published a step-by-step guide for self-hosting the n8n workflow automation tool on a single Linux VPS using two Docker containers (n8n and Caddy) with automatic HTTPS via Caddy's reverse proxy. The guide emphasizes starting only the n8n container first and creating the owner account through an SSH tunnel, since the first person to open a fresh n8n instance claims the owner account. It also covers DNS A/AAAA records, opening ports 80 and 443, installing Docker from its official repository, and pinning a specific stable image version instead of the latest tag.", "body_md": "n8n is a workflow automation tool: you connect apps, APIs, AI models and scripts as boxes on a canvas, and the workflows run on their own. The cloud version is easy, but self-hosting gives you your own data, no per-execution pricing, and a server that keeps running while your laptop is asleep.\n\nThis guide sets it up on a single Linux VPS. It is short on purpose: two containers, one config file, automatic HTTPS.\n\n`n8n.example.com`.\nA note on the licence: the self-hosted Community Edition is free for your own internal business or personal use under the n8n Sustainable Use License. Read it before you host n8n for clients.\n\nAt your DNS provider, add an **A record** for `n8n` with your server's IPv4 address. Check it from your own computer:\n\n```\nnslookup n8n.example.com\n```\n\nThe answer should be your server's address. This usually takes a few minutes. If there is also an **AAAA** (IPv6) record for that name that does not point to this server, remove it, or the certificate step can fail.\n\nPorts **80 and 443** must be reachable from the internet. If your provider has a firewall in its control panel, open them there too.\n\nThe Docker in Ubuntu's default repository is often old, so use Docker's repository, as their Ubuntu guide describes:\n\n```\napt update && apt -y upgrade\napt install -y ca-certificates curl\ninstall -m 0755 -d /etc/apt/keyrings\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc\nchmod a+r /etc/apt/keyrings/docker.asc\necho \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo \"$VERSION_CODENAME\") stable\" > /etc/apt/sources.list.d/docker.list\napt update\napt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin\n```\n\nThe idea:\n\n`127.0.0.1:5678`, so it is never reachable from the internet directly.\n\n```\nmkdir -p /opt/n8n && cd /opt/n8n\nnano compose.yaml\nname: n8n\nservices:\n  n8n:\n    image: docker.n8n.io/n8nio/n8n:VERSION   # replace VERSION, see below\n    restart: unless-stopped\n    ports:\n      - \"127.0.0.1:5678:5678\"\n    environment:\n      - N8N_HOST=n8n.example.com\n      - N8N_PROTOCOL=https\n      - WEBHOOK_URL=https://n8n.example.com/\n      - N8N_PROXY_HOPS=1\n      - GENERIC_TIMEZONE=Europe/London\n      - TZ=Europe/London\n    volumes:\n      - n8n_data:/home/node/.n8n\n  caddy:\n    image: caddy:2\n    restart: unless-stopped\n    ports:\n      - \"80:80\"\n      - \"443:443\"\n    command: caddy reverse-proxy --from n8n.example.com --to n8n:5678\n    volumes:\n      - caddy_data:/data\nvolumes:\n  n8n_data:\n    name: n8n_data\n  caddy_data:\n    name: caddy_data\n```\n\nReplace `n8n.example.com` (three places) and the time zone with your own, and replace `VERSION` with a complete stable version number from the [n8n release notes](https://docs.n8n.io/release-notes/) (Compose will fail if you leave the word `VERSION` in).\n\nWhy these settings:\n\n`latest` tag means `docker compose pull` never jumps to a new major version by surprise. You choose when to upgrade (step 7).`name: n8n` and the named volumes`n8n_data`, `caddy_data`), so the backup command in step 6 always finds the right data.`WEBHOOK_URL` makes n8n show the public HTTPS address in webhook nodes, not `localhost`.` N8N_PROXY_HOPS=1` tells n8n there is one reverse proxy in front of it, so it reads the real client IP from Caddy's headers.\nThis is the step most guides skip. **The first person to open a fresh n8n creates the owner account.** If you start Caddy first, anyone who finds your subdomain before you do can claim your instance.\n\nSo start only n8n:\n\n```\ndocker compose up -d n8n\n```\n\nOn your own computer, open an SSH tunnel and keep the window open:\n\n```\nssh -L 5678:127.0.0.1:5678 root@YOUR.SERVER.IP\n```\n\nOpen `http://localhost:5678` in **Chrome or Firefox** and create the owner account with a strong password. (Safari refuses the n8n login over plain `http://localhost`, so use another browser for this one step.)\n\nNow start everything and close the tunnel:\n\n```\ndocker compose up -d\n```\n\nOpen `https://n8n.example.com`. If it does not load straight away, give Caddy a minute to get the certificate and check:\n\n```\ndocker compose logs caddy\nufw allow OpenSSH\nufw enable\n```\n\n(If SSH runs on another port, allow that port instead.)\n\nOne gotcha worth knowing: **ports published by Docker bypass ufw.** Here only Caddy publishes 80/443 and n8n is bound to `127.0.0.1`, so that is fine. But if you later add a database or another container with `ports: - \"5432:5432\"`, it will be open to the whole internet even though ufw \"denies\" it. Bind such ports to `127.0.0.1` or leave them out.\n\nEverything that matters (workflows, credentials and the **encryption key** that unlocks those credentials) lives in the `n8n_data` volume. Lose the key and your saved credentials are useless, so back up the whole volume, not just an export of workflows.\n\nFirst make sure the volume really exists, because `docker run` would otherwise quietly create an empty one and you would back up nothing. This should print `n8n_data`; if it prints nothing, stop here and check your compose file:\n\n```\ndocker volume ls -q --filter name='^n8n_data$'\n```\n\nFor a consistent copy, stop n8n for a few seconds:\n\n```\ncd /opt/n8n\ndocker compose stop n8n\ndocker run --rm -v n8n_data:/data:ro -v /opt/n8n:/backup alpine tar czf /backup/n8n-backup.tgz -C /data .\nchmod 600 n8n-backup.tgz\ndocker compose start n8n\nls -lh n8n-backup.tgz\n```\n\nThe file should be more than a few kilobytes. It contains your credentials and encryption key, so treat it like a password: copy it off the server (for example with `scp`) to somewhere private, and do not leave copies lying around. A backup that lives on the same server is not a backup.\n\nTo restore: use the same compose file with the **same n8n version that made the backup** (upgrade afterwards, not during), put the file in `/opt/n8n` and run the block below. It **overwrites** whatever is in the `n8n_data` volume, and each step only runs if the one before it worked, so n8n is not started on half-restored data:\n\n```\ncd /opt/n8n &&\ndocker compose stop n8n &&\ndocker volume create n8n_data &&\ndocker run --rm -v n8n_data:/data -v /opt/n8n:/backup:ro alpine \\\n  sh -c 'find /data -mindepth 1 -maxdepth 1 -exec rm -rf -- {} + && tar xzf /backup/n8n-backup.tgz -C /data' &&\ndocker compose up -d\n```\n\nIf any step prints an error, stop and fix that before going on.\n\nPick the new version in the n8n release notes and read what changed (especially for a new major version). Take a backup as above, change the version number in `compose.yaml`, then:\n\n```\ncd /opt/n8n\ndocker compose pull && docker compose up -d\n```\n\nIf something breaks, put the old version number back and run the same command; restore the backup if the new version already changed your data.\n\nThat is the whole setup: one file, two containers, HTTPS, a private first login, a firewall and a backup you can actually restore. From here you can add a PostgreSQL database or queue mode when you outgrow the defaults, but for most personal and small-team automation this is plenty.\n\nI work on [HostingBaba](https://hostingbaba.net), a Linux and Windows VPS host, and we keep a longer version of this guide with plan sizing notes at [hostingbaba.net/n8n-vps](https://hostingbaba.net/n8n-vps). The steps above work on any Ubuntu 24.04 server, wherever it runs.\n\n*n8n is a trademark of n8n GmbH. This post is not affiliated with or endorsed by n8n.*", "url": "https://wpnews.pro/news/self-host-n8n-on-a-vps-with-docker-and-caddy-and-claim-the-owner-account-before", "canonical_source": "https://dev.to/jeemmo/self-host-n8n-on-a-vps-with-docker-and-caddy-and-claim-the-owner-account-before-anyone-else-does-2bkk", "published_at": "2026-11-21 09:38:23+00:00", "updated_at": "2026-11-21 09:42:11.290164+00:00", "lang": "en", "topics": ["ai-tools", "developer-tools", "ai-agents"], "entities": ["n8n", "Docker", "Caddy", "Ubuntu", "Linux"], "also_reported_by": [], "takeaway": "Start only the n8n container before Caddy and create the owner account via an SSH tunnel to 127.0.0.1:5678, because the first person to open a fresh n8n instance claims the owner account.", "recommendation": {"advice": "Bind n8n to 127.0.0.1 and bring up only the n8n container first, then claim the owner account through an SSH tunnel before exposing Caddy on ports 80 and 443.", "playbook": "production-ops", "playbook_url": "https://wpnews.pro/playbooks/production-ops"}, "alternates": {"html": "https://wpnews.pro/news/self-host-n8n-on-a-vps-with-docker-and-caddy-and-claim-the-owner-account-before", "markdown": "https://wpnews.pro/news/self-host-n8n-on-a-vps-with-docker-and-caddy-and-claim-the-owner-account-before.md", "text": "https://wpnews.pro/news/self-host-n8n-on-a-vps-with-docker-and-caddy-and-claim-the-owner-account-before.txt", "jsonld": "https://wpnews.pro/news/self-host-n8n-on-a-vps-with-docker-and-caddy-and-claim-the-owner-account-before.jsonld"}}