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.
This guide sets it up on a single Linux VPS. It is short on purpose: two containers, one config file, automatic HTTPS.
What you need
- A Linux VPS with Ubuntu 24.04 LTS and SSH access as root.
- A domain or subdomain you control, for example
n8n.example.com. - Memory: n8n itself is light, but every workflow that runs at the same time and every big payload it handles uses RAM. 4 vCPU / 8 GB is a comfortable start for personal and small-team use. Running AI models on the server needs much more; calling an AI provider's API does not.
A 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.
1. Point your subdomain at the server
At your DNS provider, add an A record for n8n with your server's IPv4 address. Check it from your own computer:
nslookup n8n.example.com The 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.
Ports 80 and 443 must be reachable from the internet. If your provider has a firewall in its control panel, open them there too.
2. Install Docker (from Docker's own repository)
The Docker in Ubuntu's default repository is often old, so use Docker's repository, as their Ubuntu guide describes:
apt update && apt -y upgrade apt install -y ca-certificates curl install -m 0755 -d /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc chmod a+r /etc/apt/keyrings/docker.asc echo "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 apt update apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin 3. One compose file: n8n + Caddy
The idea:
- n8n listens only on
127.0.0.1:5678, so it is never reachable from the internet directly. - Caddy is the only thing on ports 80 and 443. It gets a free, publicly trusted HTTPS certificate by itself (from Let's Encrypt or ZeroSSL) and forwards traffic to n8n.
mkdir -p /opt/n8n && cd /opt/n8n nano compose.yaml name: n8n services: n8n: image: docker.n8n.io/n8nio/n8n:VERSION # replace VERSION, see below restart: unless-stopped ports: - "127.0.0.1:5678:5678" environment: - N8N_HOST=n8n.example.com - N8N_PROTOCOL=https - WEBHOOK_URL=https://n8n.example.com/ - N8N_PROXY_HOPS=1 - GENERIC_TIMEZONE=Europe/London - TZ=Europe/London volumes: - n8n_data:/home/node/.n8n caddy: image: caddy:2 restart: unless-stopped ports: - "80:80" - "443:443" command: caddy reverse-proxy --from n8n.example.com --to n8n:5678 volumes: - caddy_data:/data volumes: n8n_data: name: n8n_data caddy_data: name: caddy_data Replace 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 (Compose will fail if you leave the word VERSION in).
Why these settings:
- A fixed version instead of the default
latesttag meansdocker compose pullnever jumps to a new major version by surprise. You choose when to upgrade (step 7). -
name: n8nand the named volumes keep the volume names fixed (n8n_data,caddy_data), so the backup command in step 6 always finds the right data. -
WEBHOOK_URLmakes n8n show the public HTTPS address in webhook nodes, notlocalhost. -
N8N_PROXY_HOPS=1tells n8n there is one reverse proxy in front of it, so it reads the real client IP from Caddy's headers. - The
caddy_datavolume keeps your certificates, so a restart does not ask Let's Encrypt for a new one every time.
4. Claim the owner account privately, then go public
This 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.
So start only n8n:
docker compose up -d n8n On your own computer, open an SSH tunnel and keep the window open:
ssh -L 5678:127.0.0.1:5678 root@YOUR.SERVER.IP Open 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.)
Now start everything and close the tunnel:
docker compose up -d Open https://n8n.example.com. If it does not load straight away, give Caddy a minute to get the certificate and check:
docker compose logs caddy 5. Firewall
ufw allow OpenSSH ufw enable (If SSH runs on another port, allow that port instead.)
One 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.
6. Backups
Everything 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.
First 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:
docker volume ls -q --filter name='^n8n_data$' For a consistent copy, stop n8n for a few seconds:
cd /opt/n8n docker compose stop n8n docker run --rm -v n8n_data:/data:ro -v /opt/n8n:/backup alpine tar czf /backup/n8n-backup.tgz -C /data . chmod 600 n8n-backup.tgz docker compose start n8n ls -lh n8n-backup.tgz The 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.
To 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:
cd /opt/n8n && docker compose stop n8n && docker volume create n8n_data && docker run --rm -v n8n_data:/data -v /opt/n8n:/backup:ro alpine \ sh -c 'find /data -mindepth 1 -maxdepth 1 -exec rm -rf -- {} + && tar xzf /backup/n8n-backup.tgz -C /data' && docker compose up -d If any step prints an error, stop and fix that before going on.
7. Updates
Pick 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:
cd /opt/n8n docker compose pull && docker compose up -d If something breaks, put the old version number back and run the same command; restore the backup if the new version already changed your data.
Things that commonly go wrong
- Webhooks show
localhost-WEBHOOK_URLis missing or wrong. - Caddy cannot get a certificate - the A record does not point to this server yet, a stale AAAA record points elsewhere, ports 80/443 are blocked by a provider firewall, or something else is already using them.
- "Connection lost" in the editor - n8n restarting, a network hiccup or the server running out of memory are common causes. Another possible one is an extra proxy or CDN in front that does not pass WebSockets (Caddy itself passes them by default).
- Lost credentials after moving servers - the new instance has a different encryption key. Restore the whole
n8n_datavolume, not just workflow JSON.
Wrapping up
That 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.
I work on HostingBaba, a Linux and Windows VPS host, and we keep a longer version of this guide with plan sizing notes at hostingbaba.net/n8n-vps. The steps above work on any Ubuntu 24.04 server, wherever it runs.
n8n is a trademark of n8n GmbH. This post is not affiliated with or endorsed by n8n.