01
Before you start
n8n is an automation tool: workflows that connect your applications, run on a schedule or on a webhook, and keep running without your computer switched on. To host it, you need:
- A Linux VPS running Debian 12, Ubuntu 22.04 or Ubuntu 24.04, with root access.
- Docker and Docker Compose, installed with Docker's official script: everything is explained in the guide installing Docker on a VPS.
- A domain name (for example
n8n.example.com) with a DNS A record pointing to the VPS's IPv4 address. Without it there is no HTTPS certificate, and most services refuse to call a webhook over plain HTTP.
- Ports 80 and 443 free on the VPS: Caddy needs them to obtain the Let's Encrypt certificate.
Memory. n8n's Docker Compose installation page asks for at least 4 GB of memory and 2 vCPUs, for its full stack, which adds the AI assistant's sandbox. The stack in this guide, without that sandbox, is lighter, and usage mostly depends on your workflows: a workflow that processes large files or long lists of data keeps part of them in memory while it runs. Keep an eye on it during the first weeks with docker stats.
Container or virtual machine. n8n, PostgreSQL, Caddy and the task runner need no kernel module: they run in a container VPS (LXC) as long as nesting is enabled for Docker. There is one exception: n8n Assistant, the built-in AI assistant, requires a sandbox to run code. The self-hosted options described by n8n need either a privileged Docker container started inside Docker (for development only, on a machine that does nothing else) or Kubernetes with Sysbox and a kernel module: neither belongs in a container VPS. The option hosted by an external provider works from any VPS, but the data sent to the sandbox then leaves your server. The installation below does not set up the assistant; the AI nodes in your workflows, which call an external API, work normally. The differences between the two kinds of VPS are in KVM or LXC VPS.
Do the basic security settings first (SSH key, automatic updates): the guide securing a Linux VPS gives the order to follow. The commands in this guide are typed as root (sudo -i).
02
Prepare the folder and the secrets
Everything lives in one folder: the Compose file, the Caddy configuration and a .env file holding the n8n version and the secrets. Generate random secrets right away:
mkdir -p /opt/n8n && cd /opt/n8n
cat > .env <<EOF
N8N_VERSION=2.49.9
N8N_DOMAINE=n8n.example.com
POSTGRES_USER=n8n
POSTGRES_DB=n8n
POSTGRES_PASSWORD=$(openssl rand -hex 24)
N8N_ENCRYPTION_KEY=$(openssl rand -hex 32)
RUNNERS_AUTH_TOKEN=$(openssl rand -hex 32)
EOF
chmod 600 .env
cat .env
N8N_VERSION: the latest stable release, listed on n8n's releases page on GitHub (2.49.9 as of 30 November 2026). Always pin a number rather than latest: that way you choose when updates happen.
N8N_DOMAINE: replace n8n.example.com with your subdomain.
N8N_ENCRYPTION_KEY: the key that encrypts the credentials (passwords, API tokens) stored in n8n. It must be set before the first start, and you must keep it safe: without it, a restored database can no longer decrypt your credentials.
RUNNERS_AUTH_TOKEN: the secret shared between n8n and the container that runs your workflows' code.
Copy the contents of .env into your password manager straight away. And never run this command again once n8n has started: it would replace the database password and the encryption key.
03
Install n8n, PostgreSQL and Caddy step by step
Create /opt/n8n/compose.yaml (nano compose.yaml). It follows n8n's official PostgreSQL example, with a task runner in external mode, and adds Caddy for HTTPS:
name: n8n
services:
postgres:
image: postgres:18
restart: always
environment:
- POSTGRES_USER
- POSTGRES_PASSWORD
- POSTGRES_DB
- PGDATA=/var/lib/postgresql/data
volumes:
- db_storage:/var/lib/postgresql/data
healthcheck:
test: ['CMD-SHELL', 'pg_isready -h localhost -U ${POSTGRES_USER} -d ${POSTGRES_DB}']
interval: 5s
timeout: 5s
retries: 10
n8n:
image: docker.n8n.io/n8nio/n8n:${N8N_VERSION}
restart: always
environment:
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_PORT=5432
- DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
- DB_POSTGRESDB_USER=${POSTGRES_USER}
- DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
- N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
- N8N_HOST=${N8N_DOMAINE}
- N8N_PROTOCOL=https
- N8N_EDITOR_BASE_URL=https://${N8N_DOMAINE}/
- N8N_WEBHOOK_URL=https://${N8N_DOMAINE}/
- N8N_PROXY_HOPS=1
- NODE_ENV=production
- GENERIC_TIMEZONE=Europe/Paris
- TZ=Europe/Paris
- N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
- N8N_RUNNERS_MODE=external
- N8N_RUNNERS_AUTH_TOKEN=${RUNNERS_AUTH_TOKEN}
- N8N_RUNNERS_BROKER_LISTEN_ADDRESS=0.0.0.0
volumes:
- n8n_data:/home/node/.n8n
depends_on:
postgres:
condition: service_healthy
n8n-runner:
image: n8nio/runners:${N8N_VERSION}
restart: always
environment:
- N8N_RUNNERS_AUTH_TOKEN=${RUNNERS_AUTH_TOKEN}
- N8N_RUNNERS_TASK_BROKER_URI=http://n8n:5679
depends_on:
- n8n
caddy:
image: caddy:2
restart: always
ports:
- "80:80"
- "443:443"
- "443:443/udp"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
depends_on:
- n8n
volumes:
db_storage:
n8n_data:
caddy_data:
caddy_config:
Then create /opt/n8n/Caddyfile, with your own subdomain:
n8n.example.com {
reverse_proxy n8n:5678
}
Check that DNS points to the VPS (dig +short n8n.example.com must return its IPv4 address), then start:
cd /opt/n8n
docker compose up -d
docker compose ps
docker compose logs -f n8n
On first start, n8n creates its tables in PostgreSQL, then the log says the editor is reachable. Caddy gets the certificate within a minute. curl -sf https://n8n.example.com/healthz should answer.
Create the owner account immediately. The first person to open https://n8n.example.com sees the owner setup screen and becomes the instance's administrator: do not leave that screen open to anyone.
Note that no port of n8n (5678) or PostgreSQL (5432) is published: the containers talk over Docker's internal network, and only Caddy is reachable from the internet.
04
Webhooks: the right public address
Behind a reverse proxy, n8n listens on port 5678 while the public arrives over HTTPS on port 443. Without any setting, it builds its webhook address from its own port and shows a URL like http://localhost:5678/…, which other services cannot use. Three variables in the Compose file fix this:
N8N_WEBHOOK_URL: the public address, used to display and register webhooks. It exists since n8n 2.30.0; on older versions, the variable is called WEBHOOK_URL, a name still accepted but deprecated since n8n 2.35.0.
N8N_PROXY_HOPS=1: tells n8n that one proxy (Caddy) sits in front of it, so it trusts the X-Forwarded-For, X-Forwarded-Host and X-Forwarded-Proto headers. Caddy adds them by default.
N8N_EDITOR_BASE_URL: the editor's address, used in emails sent by n8n and in sign-in redirects.
Each Webhook node has two addresses. The test URL (/webhook-test/…) only answers while you click Listen for Test Event in the editor, and shows the data received. The production URL (/webhook/…) only works once the workflow is published; its executions are listed in the Executions tab. To try it from the VPS:
curl -X POST https://n8n.example.com/webhook/mon-chemin \
-H 'Content-Type: application/json' \
-d '{"bonjour": "monde"}'
A production webhook is public by nature: in the node's settings, choose an authentication method (Basic, header or JWT) or restrict the allowed IP addresses. The maximum request size is 16 MB by default, adjustable with the N8N_PAYLOAD_SIZE_MAX variable.
05
Firewall and security
Open only SSH and the web:
apt install -y ufw
ufw allow OpenSSH
ufw allow 80/tcp
ufw allow 443/tcp
ufw allow 443/udp
ufw enable
Careful: ports published by Docker go ahead of UFW's rules: a port you added under ports: would be open to the whole world even if UFW blocks it. That is why n8n and PostgreSQL publish no port. The guide installing Docker on a VPS details this trap.
On the n8n side, a few settings really matter:
- The external task runner (the
n8n-runner container): the n8n documentation describes it as the only barrier between code typed in a Code node and your database, encryption key and credentials. Keep it, and keep it on the same version as n8n.
- Two-factor authentication: turn it on for the owner account, in n8n's personal settings, then for every account you invite.
- The public API: if you do not use it, add
N8N_PUBLIC_API_DISABLED=true to the n8n service's environment.
- Environment variables: since n8n 2.0,
N8N_BLOCK_ENV_ACCESS_IN_NODE defaults to true and stops the code in your workflows from reading the container's variables, including the encryption key. Do not set it back to false, especially if other people edit your workflows.
- The
.env file stays at chmod 600 and never goes into a Git repository.
After changing the Compose file, apply it with docker compose up -d.
06
Backups and updates
A complete n8n backup is three things: the PostgreSQL database (workflows, encrypted credentials, users, history), the n8n_data volume mounted on /home/node/.n8n, and the encryption key, here in .env. Without the key, restored credentials are unreadable.
cd /opt/n8n
mkdir -p sauvegardes
docker compose exec -T postgres pg_dump -U n8n -d n8n -Fc > sauvegardes/n8n-db-$(date +%F).dump
docker run --rm -v n8n_n8n_data:/data:ro -v /opt/n8n/sauvegardes:/out alpine \
tar czf /out/n8n-data-$(date +%F).tar.gz -C /data .
cp .env sauvegardes/env-$(date +%F)
chmod 600 sauvegardes/*
The volume name (n8n_n8n_data) comes from the name: n8n line in the Compose file; docker volume ls shows it. Then copy the sauvegardes folder off the VPS (scp, rsync or external storage): a backup left on the same machine protects against nothing. To restore the database, first stop n8n (docker compose stop n8n n8n-runner), then: docker compose exec -T postgres pg_restore -U n8n -d n8n --clean --if-exists < sauvegardes/n8n-db-AAAA-MM-JJ.dump.
Updating n8n. First read the release notes of every version you skip, especially when moving to a new major version, take a backup, then change the number in .env: it applies to both n8n and n8n-runner, which must stay on the same version.
cd /opt/n8n
nano .env
docker compose pull
docker compose down
docker compose up -d
docker compose logs -f n8n
n8n applies its own database migrations at startup. Going back to the old image does not undo them: if something goes wrong, the backup is what takes you back. Do not change PostgreSQL's major version (postgres:18) by editing the number alone either: a new major version does not read the old one's files, so you have to export and re-import the database.
Finally, cap the size of Docker's logs (the /etc/docker/daemon.json file, explained in the Docker guide): otherwise a chatty workflow can fill the disk.
07
On a CloudFive VPS, and when it is not the right choice
CloudFive has no ready-made n8n plan: you install it on a VPS with the method in this guide.
- the Ryzen VPS, on a Ryzen 9 9950X with DDR5 memory and NVMe storage, runs workflows fast and keeps the editor responsive;
- the Intel VPS, on a Xeon E5-2687W v4 with DDR4 ECC memory, is enough for regular automations without large volumes;
- both are Linux containers (LXC) with nesting enabled: Docker and Docker Compose install with the official script, and the whole stack in this guide runs there. Root access, a dedicated IPv4 address, a 1 Gb/s port and basic DDoS protection are included;
- from the customer area, the emergency console gives you back control if you lock yourself out with the firewall, and a snapshot before each n8n update lets you roll back in minutes.
Servers are in France, which keeps your automation data (credentials, processed content) in the country. Billing is monthly with no commitment, and support answers in French by ticket, on Discord and by phone, 7 days a week. Prices are on the pricing page. To choose a tier, see choosing a VPS.
It is not the right choice if:
- you do not want to administer anything: a VPS means keeping the system, Docker and n8n up to date, and checking the backups;
- you want to host the n8n Assistant sandbox yourself, which requires a privileged Docker container or Kubernetes with Sysbox, on a machine reserved for it: take a dedicated server;
- you expect a very large volume of executions, with n8n's queue mode (Redis and several workers): a dedicated server gives more headroom;
- you plan to resell n8n as a service to your own customers: n8n is distributed under a fair-code license that governs that use. Read it before you start.
08
Frequently asked questions
How do I install n8n on a VPS?
Install Docker and Docker Compose, create a folder with a .env file (version, domain, PostgreSQL password, encryption key) and a compose.yaml that runs n8n, PostgreSQL, the task runner and Caddy, then start everything with docker compose up -d and create the owner account right away.
How do I put n8n behind HTTPS with a domain name?
Point a subdomain to the VPS's IPv4, open ports 80 and 443, and put Caddy in front of n8n with a Caddyfile containing the domain and reverse_proxy n8n:5678. Caddy obtains and renews the Let's Encrypt certificate on its own.
Why do my n8n webhooks show localhost:5678?
Because n8n builds the address from its own port when it does not know it sits behind a proxy. Set N8N_WEBHOOK_URL to your public https address (WEBHOOK_URL before n8n 2.30.0) and N8N_PROXY_HOPS=1, then restart with docker compose up -d.
How do I update n8n installed with Docker?
Back up the database and the n8n_data volume, change N8N_VERSION in the .env file (the same version is used by n8n and the task runner), then run docker compose pull, docker compose down and docker compose up -d. Read the release notes before moving to a new major version.
How do I back up a self-hosted n8n instance?
You need three things: a PostgreSQL export made with pg_dump, an archive of the volume mounted on /home/node/.n8n and the N8N_ENCRYPTION_KEY encryption key. Without that key, restored credentials cannot be decrypted. Copy everything off the VPS.
Does n8n run on a CloudFive VPS?
Yes. CloudFive's Ryzen and Intel VPS are LXC containers with nesting enabled: Docker, n8n, PostgreSQL and Caddy run on them. Only the self-hosted sandbox of n8n Assistant, which needs a privileged container or Kubernetes, should go on a dedicated server.