VPSGauge

How to Self Host n8n on a VPS (Ubuntu 24.04, Docker Compose + Caddy)

Updated Nov 14, 2026 · by Kane · how we check

Part of VPS for AI agents, our guide to this topic

This guide has no affiliate links in the steps.

Live data the 2 prices on this page come from the provider's own sites, read daily. Last read Dec 1, 2026 · last price change Oct 11, 2026 (Hetzner CX23 $6.99 → $7.09).

Short answer

To self host n8n, rent a Linux VPS with at least 2 GB of RAM, point a subdomain at it, and run n8n behind Caddy with Docker Compose. Set the encryption key and webhook URL before the first start, create the owner account straight away, and back up the n8n_data volume off the server. Plan on about 45 minutes.

Time
45 min
Steps
8
Works on
Ubuntu
24.04 LTS
On this page
  1. Or use n8n Cloud?
  2. What you need before you start
  3. How to self-host n8n on Ubuntu 24.04: 8 steps
    1. 1Point a subdomain at your server
    2. 2Install Docker from Docker’s apt repository
    3. 3Create the project folder and .env file
    4. 4Write the Docker Compose file
    5. 5Configure Caddy for HTTPS
    6. 6Open the firewall and start n8n
    7. 7Create the owner account
    8. 8Back up the n8n_data volume
  4. Key takeaways
  5. A VPS for this guide
  6. Updating your n8n self hosted instance
  7. Common n8n self-hosting problems
  8. Questions

Self host n8n or use n8n Cloud?

n8n itself is cautious here. n8n’s Docker Compose guide says self-hosting is for expert users, and that mistakes can cost you data, security and uptime. If you’ve never run a server, it points you to n8n Cloud. If you’re fine with SSH and Docker, a VPS is the cheaper path for most people.

n8n docs, Docker Compose page: n8n recommends self-hosting for expert users; mistakes can lead to data loss, security issues and downtime, and if you aren’t experienced at managing servers n8n recommends n8n Cloud. n8n’s own docs steer server beginners to n8n Cloud. Source: docs.n8n.io, captured Nov 20, 2026.

Cost. The n8n pricing page (read Nov 14, 2026) lists Cloud Starter at $20 a month billed annually ($24 month to month; prices show in euros in Europe). That covers 2,500 workflow executions a month and 5 at once. Pro is $50 a month billed annually ($60 month to month) for 10,000 executions. A self-hosted Community edition has no execution cap from n8n; the server sets your limits. A 4 GB Hetzner CX23 costs $7.09 in our data, so the VPS wins on price as soon as you’d need Starter. Cloud wins if you don’t want to patch, back up and watch a server.

Licence. The free edition runs under n8n’s Sustainable Use License. n8n calls it fair-code, not open source. Its License FAQ gives the short version: if only you or people in your organization create or edit workflows, it’s free. You can use it for your business or personal projects, run several instances, and charge clients for building and maintaining workflows on your instance. You can’t host n8n as a service where clients build their own workflows, let outside users configure workflows through your product, or white-label it.

n8n License FAQ: if workflows are only created or modified by you or people in your organization, you can use n8n under the Community license for free. Who builds the workflows decides whether the free licence covers you. Source: docs.n8n.io, captured Nov 20, 2026.

WHO CREATES OR EDITS THE WORKFLOWS? you or your team even for paying clients FREE COMMUNITY EDITION Sustainable Use License, self-hosted your clients or users in n8n or via your product NEEDS A COMMERCIAL AGREEMENT ask license@n8n.io or sales@n8n.io
WHO CREATES OR EDITS THE WORKFLOWS? you or your team even for paying clients FREE COMMUNITY EDITION Sustainable Use License, self-hosted your clients or users in n8n or via your product NEEDS A COMMERCIAL AGREEMENT ask license@n8n.io or sales@n8n.io

Features. n8n’s Compare editions page lists what the Community edition leaves out: SSO (SAML, LDAP), projects, sharing workflows and credentials, Git version control, environments, external secrets, custom variables, log streaming, external storage for binary data, and multi-main mode. A free registration adds folders, debug in editor and custom execution data. Solo users rarely miss the rest; teams notice the missing sharing first.

n8n docs, Compare editions: the list of features the Community edition leaves out, with Sharing (workflows, credentials) highlighted: only the instance owner and the user who creates them can access workflows and credentials; Projects, SSO and Git version control are listed around it. Without sharing, each workflow stays with its creator and the instance owner. Source: docs.n8n.io, captured Nov 20, 2026.

What you need before you start

  • A VPS with Ubuntu 24.04 and a sudo user. New to servers? Here’s what a VPS actually is.
  • A domain where you can add DNS records.
  • 20 minutes of hardening done first. Follow our new VPS setup checklist: SSH keys, ufw, automatic security updates. n8n will hold API keys for every service it touches.

How much RAM? n8n’s Hetzner guide says the CPX11 (2 GB) is enough for most usage levels. That older plan now costs $21.09 in our data, more than the 4 GB CX23 at $7.09. Plan for 4 GB and 2 vCPU if you’ll turn on n8n Assistant, whose code sandbox needs that much. Also plan for 4 GB if your workflows move big files or run heavy Code nodes. n8n puts no cap on how much data a node loads, so one large spreadsheet can use up a small server. For agent-style workloads, our VPS for AI agents list sorts plans by memory.

n8n docs, Hetzner guide: for most usage levels the CPX11 type is enough; if you plan to add n8n Assistant, choose a plan with at least 4 GB RAM and 2 vCPU, because CPX11 lacks headroom once the sandbox is added. 2 GB covers most use; n8n Assistant needs 4 GB and 2 vCPU. Source: docs.n8n.io, captured Nov 20, 2026.

How to self-host n8n on Ubuntu 24.04: 8 steps

This follows n8n’s Hetzner guide, which pairs n8n with Caddy, with two changes from n8n’s other docs: an encryption key you set yourself, and port 5678 closed to the internet. Replace YOUR_DOMAIN, YOUR_TIMEZONE and the other orange words with your own values.

BROWSER / WEBHOOK CALLER YOUR VPS n8n.example.com https only 443 CADDY ports 80, 443 gets the cert N8N n8n:5678 UI + webhooks n8n_data SQLite database encryption key back this up port 5678 from the internet bound to 127.0.0.1 only
BROWSER / WEBHOOK CALLER n8n.example.com https only 443 YOUR VPS CADDY ports 80, 443 · gets the cert N8N n8n:5678 UI + webhooks n8n_data SQLite database · encryption key back up n8n_data 5678 bound to 127.0.0.1
1

Point a subdomain at your server

At your DNS provider, add an A record named n8n that points to YOUR_SERVER_IP. n8n runs on its own subdomain, such as n8n.example.com. Do this first. Caddy can only get a certificate once the name resolves to your server.

servergetent hosts n8n.YOUR_DOMAIN

Check: Your server’s IP next to the name. If nothing prints, wait a few minutes and try again.

2

Install Docker from Docker’s apt repository

Ubuntu’s own docker.io package lags behind. Use the repository from Docker’s Ubuntu install guide, which also includes the Compose plugin:

serversudo apt update
sudo apt install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Then check both tools:

serversudo docker run hello-world
sudo docker compose version
3

Create the project folder and .env file

Make a folder and generate a 64-character encryption key:

serversudo mkdir -p /opt/n8n-compose/caddy_config
cd /opt/n8n-compose
openssl rand -hex 32

Copy the key into your password manager now. n8n encrypts every saved credential with it. Without it, a restored backup’s credentials can’t be read. n8n only uses N8N_ENCRYPTION_KEY if no key exists yet, so set it before the first start.

serversudo nano /opt/n8n-compose/.env
.env — nanoDOMAIN_NAME=YOUR_DOMAIN
SUBDOMAIN=n8n
GENERIC_TIMEZONE=YOUR_TIMEZONE
N8N_ENCRYPTION_KEY=YOUR_ENCRYPTION_KEY

Use a timezone name like America/New_York or Europe/Berlin. Schedule nodes use it; without it they run on New York time. Then lock the file down with sudo chmod 600 /opt/n8n-compose/.env.

4

Write the Docker Compose file

serversudo nano /opt/n8n-compose/compose.yaml
serverservices:
  caddy:
    image: caddy:latest
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - caddy_data:/data
      - ./caddy_config:/config
      - ./caddy_config/Caddyfile:/etc/caddy/Caddyfile

  n8n:
    image: docker.n8n.io/n8nio/n8n
    restart: always
    ports:
      - "127.0.0.1:5678:5678"
    environment:
      - N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME}
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - NODE_ENV=production
      - N8N_WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
      - N8N_PROXY_HOPS=1
      - N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
      - N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
      - TZ=${GENERIC_TIMEZONE}
    volumes:
      - n8n_data:/home/node/.n8n

volumes:
  caddy_data:
    external: true
  n8n_data:
    external: true

What matters here:

  • N8N_WEBHOOK_URL is the public address n8n gives to webhook nodes. It exists from n8n 2.30.0; older versions use WEBHOOK_URL.
  • N8N_PROXY_HOPS=1 tells n8n it sits behind one reverse proxy, as n8n’s production requirements ask.
  • 127.0.0.1:5678 keeps n8n off the public internet. Docker-published ports bypass ufw rules, so a plain 5678:5678 would be open to everyone. Caddy reaches n8n over Docker’s internal network either way.
  • n8n_data holds the SQLite database and the key. SQLite suits a single user; n8n recommends PostgreSQL for busy, multi-user production.

Docker docs, Install Docker Engine on Ubuntu, firewall limitations: if you use ufw or firewalld, ports you expose with Docker bypass your firewall rules. This is why port 5678 is bound to 127.0.0.1 instead of relying on ufw. Source: docs.docker.com, captured Nov 20, 2026.

5

Configure Caddy for HTTPS

serversudo nano /opt/n8n-compose/caddy_config/Caddyfile
Caddyfile — nanon8n.YOUR_DOMAIN {
    reverse_proxy n8n:5678 {
      flush_interval -1
    }
}

This is the Caddyfile from n8n’s Hetzner guide. n8n:5678 is the service name from the compose file, and Caddy passes the X-Forwarded-* headers n8n expects by default. Caddy requests a Let’s Encrypt certificate on its own, as long as DNS points here and ports 80 and 443 are open (Caddy’s automatic HTTPS docs).

6

Open the firewall and start n8n

serversudo ufw allow 80
sudo ufw allow 443
sudo docker volume create caddy_data
sudo docker volume create n8n_data
cd /opt/n8n-compose
sudo docker compose up -d
sudo docker compose logs -f caddy

Press Ctrl+C to leave the logs once Caddy reports the certificate as obtained. The first start downloads both images and can take a few minutes.

If it fails: Caddy logs a challenge error. DNS doesn’t point here yet, or port 80 is blocked in your provider’s network firewall. Fix that, then run sudo docker compose restart caddy.

7

Create the owner account

Open https://n8n.YOUR_DOMAIN right away. A fresh instance shows an owner setup screen, and whoever completes it first becomes the owner. Your URL is public, so don’t leave it on that screen.

Pick a long password and turn on 2FA under Settings > Profile & preferences. The setup screen also offers a free licence key by email. That key adds folders and debug in editor.

8

Back up the n8n_data volume

n8n’s Back up and restore page says the .n8n folder is the whole instance on SQLite: database, users, settings and the key file. In Docker, that folder is the n8n_data volume. Stop n8n while you copy it, so the database file isn’t half-written:

n8n docs, Back up and restore: with the default SQLite database, stop n8n before copying the .n8n folder; if you run n8n in Docker, the .n8n folder lives in the n8n_data volume, mounted at /home/node/.n8n; the encryption key is required to restore credentials. In Docker, backing up n8n means backing up the n8n_data volume, with n8n stopped. Source: docs.n8n.io, captured Nov 20, 2026.

servercd /opt/n8n-compose
sudo docker compose stop n8n
sudo docker run --rm -v n8n_data:/data:ro -v /opt/n8n-backups:/backup ubuntu tar czf /backup/n8n_data-$(date +%F).tar.gz -C /data .
sudo docker compose start n8n

Then pull the file off the server, from your own computer:

your computerscp 'yourname@YOUR_SERVER_IP:/opt/n8n-backups/*.tar.gz' .

Keep a copy of .env with it. Don’t count on the n8n export:workflow --backup CLI on its own. n8n says it skips users, execution history, variables and the encryption key.

YOUR VPS OFF THE SERVER N8N_DATA VOLUME database.sqlite config (the encryption key) stop n8n /OPT/N8N-BACKUPS n8n_data-DATE.tar.gz + a copy of .env same disk: not enough scp your computer or object storage at another provider Lose the encryption key and every saved credential in the backup is unreadable.
YOUR VPS N8N_DATA VOLUME database.sqlite · config (the encryption key) stop n8n /OPT/N8N-BACKUPS n8n_data-DATE.tar.gz + .env same disk: not enough scp OFF THE SERVER your computer or object storage at another provider Lose the encryption key and every saved credential in the backup is unreadable.

Key takeaways

  1. To self host n8n you need a 2 GB VPS (4 GB for AI or big files), a subdomain, Docker Compose and Caddy.
  2. Set N8N_ENCRYPTION_KEY before the first start and keep a copy in your password manager.
  3. Bind port 5678 to 127.0.0.1: Docker’s published ports skip ufw.
  4. Claim the owner account the moment the site loads.
  5. Back up the n8n_data volume with n8n stopped, and keep a copy off the server.

A VPS for this guide

Everything above runs on a VPS with 2 GB of RAM or more. The cheapest 2 GB+ plan at each provider whose prices we read every day, IPv4 included:

Plan · providervCPU · RAM · diskYou payVisit
1 slice
InterServer · New York +2
1 vCPU·2 GB·40 GB$3.00/mo
KVM VPS Special 2 GB
RackNerd · New York +3
2 vCPU·2 GB·35 GB$3.00/mo
VPS nano G11.5s
netcup · Nuremberg
2 vCPU·2 GB·60 GB$3.36/mo
SSD VPS 2
CloudCone · USA
4 vCPU·2 GB·60 GB$3.83/mo
NVMe 2 GB
HostHatch · Amsterdam +15
1 vCPU·2 GB·10 GB$4.00/mo

Prices read Dec 4, 2026. gets that provider's deals on Telegram. Compare every 2 GB plan →

Updating your n8n self hosted instance

n8n ships a new minor version most weeks. n8n’s update guide says to update at least once a month, read the release notes for breaking changes, and take a full backup first. Run step 8, then:

n8n docs, Update n8n: update frequently to avoid jumping several versions at once, and try to update at least once a month; check the release notes for breaking changes. n8n asks for an update at least once a month. Source: docs.n8n.io, captured Nov 20, 2026.

cd /opt/n8n-compose
sudo docker compose pull
sudo docker compose down
sudo docker compose up -d

Your workflows live in the volume, so swapping the container doesn’t touch them. To pin a version instead of following the latest, change the image to docker.n8n.io/n8nio/n8n:VERSION with a number from n8n’s release notes.

Common n8n self-hosting problems

“Connection Lost”, “503” or “JavaScript heap out of memory”.n8n ran out of RAM. The Docker image restarts on its own, so it can look like a random disconnect. Process data in smaller batches (200 rows, not 10,000), move heavy work into sub-workflows, or add memory.

Webhook URLs end in :5678.n8n builds them from protocol, host and port unless N8N_WEBHOOK_URL reaches the container. On versions older than 2.30.0 the variable is WEBHOOK_URL. Fix .env or the compose file and run sudo docker compose up -d to recreate the container.

Credentials won’t decrypt after a restore.The database came back without its key. Restore the whole volume, or set the original N8N_ENCRYPTION_KEY.

Scheduled workflows fire at the wrong hour.GENERIC_TIMEZONE is missing or wrong in .env. Set it, then recreate the container.

Questions

Is self-hosted n8n free?

The Community edition is free under the Sustainable Use License, as long as only you or your organization create and edit the workflows. You still pay for the server. SSO, projects and Git sync need a paid Business or Enterprise key.

How much RAM does n8n need?

n8n’s docs say a 2 GB server covers most usage levels. Go to 4 GB and 2 vCPU for n8n Assistant, large files or heavy Code nodes.

Can I self host n8n for clients?

Yes, if you build and run the workflows and your clients only use the results. If clients create or edit workflows themselves, n8n requires a commercial agreement.

Is SQLite good enough?

For one user and modest volume, yes. n8n recommends PostgreSQL for production with several users or round-the-clock load.

Should I use Caddy or Traefik?

Either works. n8n’s generic Docker Compose guide uses Traefik; its Hetzner guide uses Caddy. Caddy needs five lines of config and no certificate email.

How we checked: The steps follow n8n’s and Docker’s official documentation as published on Nov 14, 2026. We did not run them on every provider’s images. Prices come from our daily reads of provider pages; n8n Cloud prices come from n8n’s pricing page. How we check.

Keep reading