BestVPSHosting.netVPS hosting compared RU

Updated

Blog · Tutorials

How to self-host n8n on a VPS with Docker Compose

Short answer: To self host n8n, rent a KVM VPS with 2 GB RAM, point a subdomain at it, install Docker Engine and run n8n's official Docker Compose stack, which puts Traefik in front for automatic Let's Encrypt HTTPS. The Community Edition is free under the Sustainable Use License, and the median 2 GB KVM plan costs $9.54 a month.

This guide shows how to self host n8n on a VPS the way n8n's own documentation does it: Docker Compose, a subdomain, and Traefik issuing a free Let's Encrypt certificate so the editor and webhooks run over HTTPS. It also covers Postgres versus SQLite, backups that include the encryption key, what the license allows, and what n8n self hosted costs next to n8n Cloud.

Budget about 45 minutes, most of it waiting for DNS. The commands target Ubuntu 24.04 LTS or 26.04 LTS and work the same on Debian.

Can I install n8n on a VPS?

Yes. Any KVM-based VPS that can run Docker will run n8n, and the easiest way to deploy n8n on a VPS while keeping full control is the official Docker Compose file used below. Container-based virtualization such as OpenVZ often cannot run Docker, which is why our ranking only lists KVM VPS plans.

These are the usual ways to run n8n with a VPS:

Method HTTPS Updates Good for
Docker Compose + Traefik (this guide) Automatic, Let's Encrypt docker compose pull Most single-server setups
Single docker run container None until you add a proxy Pull and recreate Local testing
npm global install (Node 20.19 to 24.x) Add Nginx or Caddy yourself npm update -g n8n plus Node upgrades Servers without Docker
Host's one-click n8n template Usually preconfigured Depends on the template Fast start, less visibility
Coolify or Dokploy Built in From the panel Running several apps on one VPS

If you would rather manage n8n from a panel alongside other apps, see our Coolify vs Dokploy comparison and the Coolify VPS ranking.

What you need to self-host n8n

n8n publishes no general server minimum. Its only sizing figures are an n8n Cloud example of 320 MB to 2 GB of memory with a 512 MB to 4 GB database, and the docs warn that memory grows with data volume, binary files, Code nodes and concurrent executions.

Item Requirement Notes
RAM 2 GB to start 4 GB or more for Postgres, many executions or large files
CPU 1 to 2 vCPU n8n gives no firm figure
Virtualization KVM Needed for Docker
OS Ubuntu 26.04, 24.04 or 22.04 LTS, or Debian All supported by Docker Engine
Domain A subdomain with an A record Required for HTTPS and public webhooks
Open ports 22, 80, 443 n8n's port 5678 stays on localhost
Database SQLite (default) or PostgreSQL See the database section below

As of November 30, 2026, 152 of the 199 providers we track sell a KVM plan with 2 GB of RAM, and the median price of each provider's cheapest 2 GB KVM plan is $9.54 a month; for 4 GB it is $15.00. The table below shows the top five of our VPS plans ranked for n8n, filtered for KVM and at least 2 GB:

#ProviderPlanSpecsPrice / monthLocations
1LikeVPSLite+2 vCPU, 2 GB RAM, 40 GB NVMe, unmetered traffic$12.0026
2ContaboCloud VPS 44 vCPU, 8 GB RAM, 100 GB SSD, unmetered traffic$6.09
prepaid annually or longer
10
3OVHcloud VPSVPS-12 vCPU, 4 GB RAM, 40 GB NVMe, unmetered traffic$4.5411
4AlphaVPSC2G2 vCPU, 2 GB RAM, 30 GB NVMe, 3 TB traffic$3.337
5netcupVPS nano G11.5s2 vCPU, 2 GB RAM, 60 GB SSD, unmetered traffic$3.435

Top 5 of 152 providers in our Best VPS for n8n ranking, updated November 30, 2026. Each plan meets the software's published minimum requirements.

Step 1: Point a subdomain at the server

Create an A record for the name you want, for example n8n under example.com, pointing to the VPS's public IPv4 address. Add an AAAA record too if the server has IPv6. Then check that it resolves before going further:

dig +short n8n.example.com

The output should be your server's IP. Starting Traefik before DNS resolves makes the Let's Encrypt challenge fail, and repeated failures can hit Let's Encrypt's rate limits.

Step 2: Prepare the server and firewall

Log in as a sudo user rather than root (our VPS security checklist covers SSH keys and users), update the system, and allow only SSH, HTTP and HTTPS:

sudo apt update && sudo apt upgrade -y
sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable

One Docker detail matters here. Docker's documentation warns that ports published by containers bypass UFW and firewalld rules. A line such as "5678:5678" in a compose file would expose n8n to the internet even with UFW enabled. The official file below avoids this by binding n8n to 127.0.0.1 only.

Step 3: Install Docker Engine and Compose

Use Docker's own apt repository rather than the docker.io package from Ubuntu. Remove any conflicting packages first:

sudo apt remove $(dpkg --get-selections docker.io docker-compose docker-compose-v2 docker-doc podman-docker containerd runc | cut -f1)

Add Docker's signing key and repository:

sudo 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

Install the engine and the Compose plugin, then test:

sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo docker run hello-world
docker compose version

To run Docker without sudo, add your user to the docker group with sudo usermod -aG docker $USER, then log out and back in. Membership in that group is equivalent to root access, so only add trusted users. Docker's get.docker.com convenience script is faster, but Docker recommends it for test and development machines only.

Step 4: Create the project folder and .env file

Create a folder for the stack and a local-files directory that the n8n container will see as /files:

mkdir ~/n8n-compose
cd ~/n8n-compose
mkdir local-files
nano .env

Put your own values in .env:

DOMAIN_NAME=example.com
SUBDOMAIN=n8n
GENERIC_TIMEZONE=America/New_York
[email protected]

SUBDOMAIN and DOMAIN_NAME together form the address, here n8n.example.com. The timezone controls schedule-based nodes, and Traefik registers your Let's Encrypt account with the email.

Step 5: Write the compose file

Create compose.yaml in the same folder. This is the file from n8n's Docker Compose guide, with the n8n image pinned to the stable release current in October 2026 (2.45.5) so updates happen when you choose:

services:
  traefik:
    image: "traefik"
    restart: always
    command:
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.web.http.redirections.entryPoint.to=websecure"
      - "--entrypoints.web.http.redirections.entrypoint.scheme=https"
      - "--entrypoints.websecure.address=:443"
      - "--certificatesresolvers.mytlschallenge.acme.tlschallenge=true"
      - "--certificatesresolvers.mytlschallenge.acme.email=${SSL_EMAIL}"
      - "--certificatesresolvers.mytlschallenge.acme.storage=/letsencrypt/acme.json"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - traefik_data:/letsencrypt
      - /var/run/docker.sock:/var/run/docker.sock:ro

  n8n:
    image: n8nio/n8n:2.45.5
    restart: always
    ports:
      - "127.0.0.1:5678:5678"
    labels:
      - traefik.enable=true
      - traefik.http.routers.n8n.rule=Host(`${SUBDOMAIN}.${DOMAIN_NAME}`)
      - traefik.http.routers.n8n.tls=true
      - traefik.http.routers.n8n.entrypoints=web,websecure
      - traefik.http.routers.n8n.tls.certresolver=mytlschallenge
      - traefik.http.middlewares.n8n.headers.SSLRedirect=true
      - traefik.http.middlewares.n8n.headers.STSSeconds=315360000
      - traefik.http.middlewares.n8n.headers.browserXSSFilter=true
      - traefik.http.middlewares.n8n.headers.contentTypeNosniff=true
      - traefik.http.middlewares.n8n.headers.forceSTSHeader=true
      - traefik.http.middlewares.n8n.headers.SSLHost=${DOMAIN_NAME}
      - traefik.http.middlewares.n8n.headers.STSIncludeSubdomains=true
      - traefik.http.middlewares.n8n.headers.STSPreload=true
      - traefik.http.routers.n8n.middlewares=n8n@docker
    environment:
      - N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
      - N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME}
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - NODE_ENV=production
      - N8N_WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
      - TZ=${GENERIC_TIMEZONE}
      - N8N_RESTRICT_FILE_ACCESS_TO=/files
    volumes:
      - n8n_data:/home/node/.n8n
      - ./local-files:/files

volumes:
  n8n_data:
  traefik_data:

What the important lines do:

  • 127.0.0.1:5678:5678 keeps n8n off the public interface; only Traefik on 80 and 443 faces the internet.
  • n8n_data is a named volume holding the SQLite database and the encryption key for saved credentials. It is the one thing you must not lose.
  • N8N_WEBHOOK_URL tells n8n its public address so webhook URLs show https://n8n.example.com/... instead of localhost:5678. It applies from n8n 2.30.0; older versions read WEBHOOK_URL, which is deprecated from 2.35.0.
  • --api.insecure=true turns on Traefik's dashboard on its internal port 8080, which this file never publishes. You can delete the line if you do not use the dashboard.
  • n8n's reverse-proxy guide also recommends N8N_PROXY_HOPS=1 whenever a proxy sits in front, so you can add it to the environment list here too.

Step 6: Start n8n and create the owner account

Start the stack in the background and watch the logs:

docker compose up -d
docker compose ps
docker compose logs -f n8n

Both containers should show as running. Open https://n8n.example.com and create the owner account. Every self-hosted instance has its own users, so an existing n8n Cloud login will not work here. If the page does not load, check DNS and that ports 80 and 443 are open. To stop the stack, run docker compose stop.

n8n environment variables worth knowing

Environment variables configure everything in a Docker install. After editing compose.yaml or .env, run docker compose up -d again: it recreates the container with the new values, while docker compose restart keeps the old ones.

Variable In this setup What it does
N8N_HOST, N8N_PROTOCOL, N8N_PORT n8n.example.com, https, 5678 The address n8n uses to build its own URLs
N8N_WEBHOOK_URL https://n8n.example.com/ Public base URL for webhooks; needed behind any proxy
N8N_PROXY_HOPS Not set Set 1 behind a reverse proxy so n8n trusts X-Forwarded-* headers
GENERIC_TIMEZONE, TZ From .env Timezone for schedule nodes and the container
N8N_ENCRYPTION_KEY Not set, so n8n generates one Encrypts saved credentials; setting it yourself makes moves and restores easier
N8N_SECURE_COOKIE true (default) Sends the login cookie over HTTPS only
N8N_BLOCK_ENV_ACCESS_IN_NODE false (default) Set true to hide environment variables from expressions and Code nodes
N8N_RESTRICT_FILE_ACCESS_TO /files Limits file nodes to the listed folders
N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS true Sets 0600 permissions on the settings file
DB_TYPE Not set (SQLite) Set postgresdb to use PostgreSQL

Reverse proxy and TLS: Traefik, Caddy or Nginx

Traefik is already your reverse proxy in this setup. It requests a certificate from Let's Encrypt through the TLS challenge on port 443, stores it in the traefik_data volume, renews it automatically and redirects HTTP to HTTPS. No Certbot cron job is needed.

If the server already runs Nginx or Caddy, remove the traefik service and its labels, keep the 127.0.0.1:5678 binding, and point your proxy at it. n8n's docs then ask for three things: set N8N_WEBHOOK_URL to the public URL, set N8N_PROXY_HOPS=1, and have the proxy pass X-Forwarded-For, X-Forwarded-Host and X-Forwarded-Proto. On Nginx, also pass the WebSocket Upgrade and Connection headers so the editor's live connection works. Caddy handles certificates, WebSockets and forwarded headers by default:

n8n.example.com {
    reverse_proxy 127.0.0.1:5678
}

SQLite or Postgres for n8n self hosted?

Keep SQLite, the default, for a personal or small-team instance. It needs no extra container, and the whole database lives in the n8n_data volume. Move to PostgreSQL when executions run into the thousands per day, several people edit at once, or you plan to use queue mode with separate workers, which needs Postgres and Redis.

Decide early: changing DB_TYPE points n8n at an empty database, so existing workflows do not move by themselves. To add Postgres, put POSTGRES_PASSWORD= with a long random value in .env, then extend compose.yaml:

services:
  postgres:
    image: postgres:16
    restart: always
    environment:
      - POSTGRES_USER=n8n
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=n8n
    volumes:
      - db_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U n8n -d n8n"]
      interval: 5s
      timeout: 5s
      retries: 10

  n8n:
    # keep everything from step 5, then add:
    depends_on:
      postgres:
        condition: service_healthy
    environment:
      # add these lines to the existing environment list
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=postgres
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=n8n
      - DB_POSTGRESDB_USER=n8n
      - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}

volumes:
  db_data:

Postgres runs as a second server process next to n8n, so plan for 4 GB of RAM once you add it and executions grow.

Backups and updates

What to back up

Back up four things: the n8n_data volume (SQLite database plus encryption key), the Postgres database if you use one, the local-files folder, and your .env and compose.yaml. Without the encryption key, a restored database opens but every saved credential fails to decrypt.

cd ~/n8n-compose
docker compose stop n8n
docker run --rm -v n8n-compose_n8n_data:/data -v "$PWD":/backup alpine tar czf /backup/n8n-data-$(date +%F).tar.gz -C /data .
docker compose start n8n

Compose prefixes volume names with the folder name, so check yours with docker volume ls. For Postgres, dump the database while it runs:

docker compose exec -T postgres pg_dump -U n8n n8n > n8n-db-$(date +%F).sql

Copy both files off the server. Provider snapshots add a second layer; 102 of the 199 providers we track offer them, and our page on snapshots vs backups explains why you want both.

How to update

Take a backup or snapshot, read the release notes for the version you are moving to, change the image tag in compose.yaml, then:

cd ~/n8n-compose
docker compose pull
docker compose up -d
docker image prune -f

The first start after an update can take longer while n8n runs database migrations. Going back to an older image after migrations have run is not guaranteed to work, which is why the backup comes first.

Is self-hosted n8n free? Licensing explained

The Community Edition is free to self-host under n8n's Sustainable Use License, a fair-code license rather than an OSI open-source one. It has no execution quota; the limit is your server.

The license allows use "for your own internal business purposes or for non-commercial or personal use", and n8n says paid consulting, such as building workflows for clients, is fine. Its example of what is not allowed: making n8n available to your customers so they can connect their accounts and build workflows. Hosting n8n as a product needs a commercial agreement with n8n.

Source files with .ee. in the name fall under the separate n8n Enterprise License. These files hold the paid features. On n8n's pricing page, the self-hosted Business plan adds SSO, LDAP, multiple environments, Git version control and six shared projects, and Enterprise adds unlimited projects, 200+ concurrent executions and SLA support.

n8n self-hosted vs n8n Cloud: what does it cost?

Self-hosting the Community Edition costs only the server. n8n Cloud and the paid self-hosted plans are priced per month with execution quotas. Prices below are from n8n's pricing page in October 2026, shown in euros with annual billing, which n8n says saves 17% over monthly billing; the currency shown varies by region.

Option Price per month Executions per month Notes
Community Edition on your VPS Median $9.54 for 2 GB, $15.00 for 4 GB No quota You handle updates, backups and security
Cloud Starter €20 2,500 5 concurrent executions
Cloud Pro €50 10,000 20 to 50 concurrent executions
Business (self-hosted only) €667 40,000 SSO, LDAP, environments, Git
Enterprise Custom Custom 200+ concurrent, SLA

All plans include unlimited users and workflows. Companies with fewer than 20 employees can get 50% off Business, and the Cloud trial includes 1,000 executions without a credit card.

For a single user, a 2 GB VPS at the median price costs less than Cloud Starter and has no execution cap. What you pay instead is time: patching the server, testing backups and fixing the occasional upgrade that changes a node. If nobody on the team wants that job, Cloud can come out cheaper once staff time is counted.

Troubleshooting self-hosted n8n

The message reads: "Your n8n server is configured to use a secure cookie, however you are either visiting this via an insecure URL, or using Safari." It appears when you open n8n over plain HTTP, usually http://SERVER-IP:5678. The fix is to use the HTTPS address Traefik serves. N8N_SECURE_COOKIE=false silences the error, but n8n marks that as not recommended; use it only on a private test box.

Webhook URL shows localhost or http

If the Webhook node displays http://localhost:5678/webhook/..., n8n does not know its public address. Set N8N_WEBHOOK_URL=https://n8n.example.com/ (or WEBHOOK_URL on versions before 2.30.0), add N8N_PROXY_HOPS=1 when a separate proxy sits in front, and run docker compose up -d. Also remember that test URLs (/webhook-test/) only answer while the editor is listening, and production URLs (/webhook/) only work once the workflow is active.

Other common errors

Symptom Likely cause Fix
Browser shows a certificate warning DNS did not resolve when Traefik started, or ports 80/443 closed Fix DNS or firewall, then docker compose restart traefik and read docker compose logs traefik
n8n reachable on IP:5678 from outside Port published as 5678:5678 Bind to 127.0.0.1:5678:5678; Docker bypasses UFW
EACCES or permission denied on /home/node/.n8n Host folder bind-mounted with root ownership sudo chown -R 1000:1000 on that folder, or use the named volume
Credentials fail to decrypt after a restore Different encryption key Restore the original n8n_data volume or set the old N8N_ENCRYPTION_KEY
Container restarts during big runs Out of memory Split large workflows, add swap or move to 4 GB

Which setup should you choose?

For one person or a small team, the compose stack above on a 2 GB KVM server with SQLite covers most automation work. Add Postgres and move to 4 GB once executions climb or more people build workflows, and look at Cloud if nobody wants to own server maintenance. To compare servers that meet these requirements, start with our n8n VPS ranking, or see VPS plans for Docker if n8n will share the machine with other containers.

Frequently asked questions

Is self-hosted n8n free?

Yes. The Community Edition costs nothing and has no execution quota, under the Sustainable Use License: use it for your own business or personal projects, and sell consulting. Offering n8n to your customers so they can build workflows needs a commercial agreement. SSO, LDAP, environments and Git version control are paid features.

How can I install n8n on a VPS without Docker?

Install Node.js 20.19 to 24.x and run npm install -g n8n, then keep it running with systemd or a process manager and put Nginx or Caddy in front for HTTPS. It works, but you manage Node upgrades yourself. Docker Compose is the path n8n documents for servers.

How much RAM does self-hosted n8n need?

n8n publishes no general minimum. Its own Cloud sizing example runs from 320 MB to 2 GB, and memory grows with data volume, binary files, Code nodes and parallel executions. 2 GB is a sensible start for Docker plus Traefik; with Postgres or heavy workflows, look at 4 GB VPS plans.

Do I need a domain to self-host n8n?

For anything public, yes. External services need an HTTPS URL to call your webhooks, and n8n's secure cookie only works over HTTPS. For a private test you can skip the domain, bind n8n to localhost and reach it through an SSH tunnel at http://localhost:5678.

Can I move workflows from n8n Cloud to my own server?

Yes. Download each workflow as JSON from Cloud and import it on the new instance. Credentials do not travel with it, so re-create them, and create a new owner account: Cloud logins do not carry over to a self-hosted instance.

How do I update self-hosted n8n?

Back up the n8n_data volume, change the image tag in compose.yaml, then run docker compose pull and docker compose up -d. Read the release notes first, because major versions include breaking changes. See the n8n VPS ranking for plans with snapshots.

Sources

Commands and requirements were checked against these pages on November 30, 2026. Prices and plan tables in the article come from our provider data, updated the same day.

  1. n8n Docs: Docker Compose server setup
  2. n8n Docs: Configure webhook URLs with a reverse proxy
  3. n8n Docs: Security environment variables
  4. n8n Docs: Sustainable Use License
  5. n8n Pricing
  6. Docker Docs: Install Docker Engine on Ubuntu