AI Tool Pipelines — Automate Your WorkflowsAI Tool Pipelines

Every product was carefully curated by an AI Tool Pipelines editor. We may earn a commission from these links. Here's how we choose products and why you should trust us.

How to Self-Host n8n on a VPS, Step by Step

By · 4 min read · Updated Dec 2, 2026

Five-step flow for self-hosting n8n on a VPS: rent server, point domain, run Docker Compose, add HTTPS, set up backups

To self-host n8n on a VPS, rent a server with at least 4 GB of RAM, point a domain at it, and run n8n in Docker behind a reverse proxy that handles HTTPS. The fast route is a host with a one-click n8n template, which does all of that for you in about ten minutes. The manual route is one Docker Compose file and about half an hour. Either way, set up backups before you build your first workflow.

Key takeaways

  • You need a VPS with 2 vCPUs and 4 GB RAM or more, a domain or subdomain, and SSH access.
  • The template route (for example Hostinger's n8n VPS) gives you a working, HTTPS-enabled n8n in about ten minutes.
  • The manual route is Docker Compose with n8n, Postgres and Caddy, which gets HTTPS certificates automatically.
  • Set N8N_ENCRYPTION_KEY yourself and store it safely. Lose it and every saved credential is unreadable.
  • Turn on execution pruning and nightly database backups on day one, not after the disk fills up.

What you need before you start

Five steps to self-host n8n on a VPS: rent a 4 GB server, point a subdomain, run Docker Compose, Caddy adds HTTPS, set up backups
  • A VPS: 2 vCPU, 4 GB RAM, Ubuntu 24.04. Our best VPS for n8n comparison covers which one to rent.
  • A domain or subdomain: something like n8n.yourdomain.com. Webhooks from Stripe, Slack and most other apps require HTTPS.
  • SSH access: a terminal and the root password or SSH key from your host.

Route 1: the one-click template

If your host offers an n8n template, this is the right call for most people. On Hostinger you pick the n8n VPS plan, choose the n8n template (or n8n with queue mode if you expect heavy traffic), set a root password, and wait for the server to build. You open the address it gives you and create your owner account.

  • Rent the plan and choose the n8n template during checkout.
  • Point your subdomain at the server's IP with an A record.
  • Set the n8n domain in the panel so webhooks use your real URL, not the IP.
  • Create the owner account in the n8n editor.
  • Turn on the host's backups and write down where your encryption key is stored.

Route 2: Docker Compose with HTTPS

If you want full control, or your host has no template, here is the setup I would run myself: n8n, Postgres for storage, and Caddy as the reverse proxy. Caddy fetches and renews HTTPS certificates on its own, which removes the most annoying part of any self-hosting guide.

Step 1: install Docker

bash
ssh root@YOUR_SERVER_IP
curl -fsSL https://get.docker.com | sh
mkdir -p ~/n8n && cd ~/n8n

Step 2: write the compose file

yaml
services:
  postgres:
    image: postgres:16
    restart: unless-stopped
    environment:
      POSTGRES_USER: n8n
      POSTGRES_PASSWORD: ${PG_PASSWORD}
      POSTGRES_DB: n8n
    volumes:
      - pg_data:/var/lib/postgresql/data

  n8n:
    image: docker.n8n.io/n8nio/n8n:latest
    restart: unless-stopped
    environment:
      DB_TYPE: postgresdb
      DB_POSTGRESDB_HOST: postgres
      DB_POSTGRESDB_USER: n8n
      DB_POSTGRESDB_PASSWORD: ${PG_PASSWORD}
      N8N_HOST: n8n.yourdomain.com
      N8N_PROTOCOL: https
      WEBHOOK_URL: https://n8n.yourdomain.com/
      N8N_ENCRYPTION_KEY: ${N8N_ENCRYPTION_KEY}
      EXECUTIONS_DATA_PRUNE: "true"
      EXECUTIONS_DATA_MAX_AGE: 168
      GENERIC_TIMEZONE: UTC
    volumes:
      - n8n_data:/home/node/.n8n
    depends_on:
      - postgres

  caddy:
    image: caddy:2
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - caddy_data:/data

volumes:
  pg_data:
  n8n_data:
  caddy_data:
docker-compose.yml: n8n, Postgres and Caddy. Execution data older than 7 days (168 hours) is pruned.

Step 3: secrets, Caddy and start

bash
cat > .env <<EOF
PG_PASSWORD=$(openssl rand -hex 16)
N8N_ENCRYPTION_KEY=$(openssl rand -hex 32)
EOF

echo "n8n.yourdomain.com {
  reverse_proxy n8n:5678
}" > Caddyfile

docker compose up -d
docker compose logs -f n8n

Open https://n8n.yourdomain.com and you should see the owner setup screen with a valid certificate. Copy the .env file somewhere safe that is not this server. That encryption key is the only thing that can decrypt your saved credentials.

Backups and updates

The one composite story I tell everyone: call her Lerato. In autumn 2025 she ran 30 client workflows on a self-hosted n8n with no backups because "the host has snapshots". A botched update corrupted the database, and the newest snapshot was eleven days old. She spent a weekend rebuilding eleven days of changes from memory. The next Monday she added a nightly pg_dump, and it has run every night since.

bash
# /etc/cron.d/n8n-backup: nightly Postgres dump, keep 14 days
0 3 * * * root cd /root/n8n && docker compose exec -T postgres pg_dump -U n8n n8n | gzip > /root/backups/n8n-$(date +\%F).sql.gz && find /root/backups -name "*.sql.gz" -mtime +14 -delete

To update n8n, run docker compose pull && docker compose up -d. Read the release notes first: n8n ships fast and occasionally changes node behaviour. My opinion: update monthly on a quiet day, never on a Friday afternoon (a lesson most of us only need once).

“Self-hosting n8n takes an afternoon. Self-hosting it well takes one extra hour: the backup, the encryption key, and the pruning setting.”

Frequently asked questions

Frequently asked questions

Can I self-host n8n for free?

Yes. The n8n Community Edition is free and has no execution limit. You only pay for the server, which starts at a few dollars a month.

What are the minimum requirements to self-host n8n?

A Linux VPS with 2 vCPUs and 4 GB of RAM handles most small and medium workloads. You can start on 2 GB, but large executions may run out of memory.

Do I need a domain to self-host n8n?

For anything that receives webhooks, yes. Most apps only send webhooks to HTTPS URLs, and you need a domain to get a certificate.

Should I use SQLite or Postgres for n8n?

SQLite is fine for testing. Use Postgres for anything you depend on: it handles concurrent executions better and is easier to back up and restore.

How do I update self-hosted n8n?

With Docker, run docker compose pull and then docker compose up -d. Take a database backup first and read the release notes.