👍 What we like
- No execution limits or operation-based costs
- Data stays on your server and never passes through a third-party cloud
- Cost reduced to the price of the server
- Automatic HTTPS and Let's Encrypt via the Caddy reverse proxy
👎 What to watch
- Technical and sensitive initial setup (keys, database)
- Requires a domain name for webhooks
- Critical risk if the encryption key is lost or changed
- Updates, backups and monitoring are your responsibility
📑 Contents ▾
- 01 Self-host n8n or pay for n8n Cloud?
- 02 n8n, Activepieces or Node-RED: which one to install?
- 03 Which server for n8n?
- 04 Prerequisites
- 05 Step 1: Install Docker and Docker Compose
- 06 Step 2: Configure DNS
- 07 Step 3: Create the shared Docker network
- 08 Step 4: Prepare the folder and the .env file
- 09 Step 5: The n8n docker-compose.yml
- 10 Step 6: The Caddyfile for automatic HTTPS
- 11 Step 7: Start the services
- 12 Step 8: Create the owner account and a first workflow
- 13 Step 9: Backups
- 14 Step 10: Final check
- 15 Securing an exposed n8n instance
- 16 Updating and monitoring n8n
- 17 Troubleshooting
- 18 Where to run n8n: VPS or mini PC
- 19 FAQ
- Our picks
To self-host n8n properly, you need a small Linux server (2 GB of RAM is enough to start), a domain name, Docker Compose with a PostgreSQL database, and a reverse proxy such as Caddy to handle HTTPS. The one thing not to get wrong is the N8N_ENCRYPTION_KEY: it protects all your API credentials, and losing it makes them unreadable. If you are still choosing the tool, n8n remains the most complete replacement for Zapier or Make; Activepieces is simpler and MIT-licensed, and Node-RED is built for IoT and home automation.
This guide starts with those choices (self-hosting or n8n Cloud, n8n or an alternative, server size), then walks through the full installation: Docker, DNS, docker-compose.yml, Caddy, first workflow, backups, hardening and updates.
Self-host n8n or pay for n8n Cloud?
n8n Cloud is the version hosted and maintained by the vendor: nothing to install, but a subscription whose plans cap the number of executions per month. The self-hosted Community edition is free and has no execution limit: only your server’s resources set the ceiling.
| Criterion | Self-hosted n8n (Community) | n8n Cloud |
|---|---|---|
| Cost | The price of the server | Monthly subscription, per n8n’s price list |
| Executions | Unlimited, within CPU and RAM limits | Capped according to the plan |
| Maintenance | Yours (updates, backups, monitoring) | Handled by n8n |
| Data | On your server | At n8n |
| Scaling | Add workers, configured by you | Handled by the chosen plan |
For a few light workflows, the cloud saves time. Self-hosting pays off once executions multiply, workflows run long (data processing, AI), or the data must not leave your infrastructure. One server can also host several instances (staging and production). Some advanced features (enterprise SSO, environments) require a paid Enterprise license, even when self-hosted.
n8n, Activepieces or Node-RED: which one to install?
All three self-host with Docker and run on Node.js, but they target different uses. The integration counts below are the ones announced by the projects and keep growing.
| Criterion | n8n | Activepieces | Node-RED |
|---|---|---|---|
| Target audience | Advanced automation, teams | Simple no-code, business teams | Makers, IoT, developers |
| Integrations | 400+ native nodes | 250+ “pieces” | Community nodes |
| Custom code | Code node (JavaScript or Python) | TypeScript pieces | Function node (JavaScript) |
| AI | LLM and agent nodes | AI pieces and copilot | Via third-party packages |
| License | Sustainable Use License (fair-code) | MIT | Apache 2.0 |
| Multi-user | Yes, depending on edition | Yes, native | Limited |
| Resources | The heaviest (2 GB to start, 4 GB with heavy Code-node or AI use) | Small VPS, with PostgreSQL and Redis | A few hundred MB, runs on a Raspberry Pi |
n8n is the default choice to replace Zapier or Make: the widest integration catalog (Google, Slack, Notion, CRMs, databases, generic HTTP), workflows with conditions, loops, data merging and error handling, and nodes to call LLMs, build agents or do RAG. Its license is not an open-source license in the OSI sense: the code is available and personal or internal company use is free, but reselling n8n as a hosted service to third parties is restricted. For a self-hoster, this changes nothing.
Activepieces suits you if you want an MIT license and a cleaner interface that is easier for non-technical profiles to pick up. Its catalog is still thinner than n8n’s for niche services, and it is less mature for very complex scenarios (advanced error handling). It installs with the same logic as this tutorial: a Node application, PostgreSQL and Redis, behind a reverse proxy.
Node-RED wires nodes together to pass messages along: ideal for MQTT, sensors, home automation and real-time data flows. It is not a direct Zapier replacement: connecting Slack, Notion or a CRM often takes a community node or a hand-built HTTP request, and team management is limited.
None of the three imports the others’ workflows: switching tools means rebuilding your flows. So choose based on the nature of your automations. The rest of this guide installs n8n.
Which server for n8n?
n8n is a Node.js application: it uses the CPU while running complex workflows, and the disk for database writes. The 1 vCPU and 512 MB RAM setups still recommended by older tutorials are too tight for production.
| Profile | CPU | RAM | Storage |
|---|---|---|---|
| Testing | 1 vCPU | 1 GB | 20 GB SSD |
| Light use, small team | 2 vCPU | 2 GB | 50 GB NVMe |
| Production, Code nodes and AI | 2 to 4 vCPU | 4 GB and more | 100 GB NVMe |
- RAM. Each active workflow adds to the load. If you use the Code node or AI steps a lot, start with 4 GB. Running a local model (Ollama) on the same machine needs far more: 16 GB of RAM and ideally a GPU.
- CPU. Parallel executions quickly saturate the “burst” vCPUs of some VPS plans. For production, prefer dedicated cores or a guaranteed CPU quota.
- Storage. Execution history and processed files (images, PDFs) pile up: NVMe storage and some headroom prevent bad surprises.
- No shared hosting or free PaaS. Their execution-time and memory limits break workflows that process batches for several minutes. A VPS (Hetzner, OVHcloud, Infomaniak…) gives you control over the firewall and resources.
- What about a NAS? Synology or QNAP run n8n through Docker. That works for notifications and simple syncs, less so for heavy workflows, because of the slower CPU and disks.
Prerequisites
- A secure VPS running Ubuntu 24.04 (or Debian 12) with at least 2 GB of RAM. If you haven’t already, first follow our guide to install and secure an Ubuntu VPS.
- Docker and Docker Compose installed (command in step 1).
- A domain name whose DNS you control. We will use
n8n.exemple.fr. It is essential: many third-party services refuse to register webhooks pointing to a bare IP address. - Ports 80 and 443 open for Let’s Encrypt and HTTPS traffic.
Step 1: Install Docker and Docker Compose
sudo apt update
sudo apt install -y 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
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" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo usermod -aG docker $USER
On Debian 12, replace ubuntu with debian in both download.docker.com URLs above (GPG key and repository). Log out and back in, then verify:
docker --version && docker compose version
Step 2: Configure DNS
At your DNS provider, create an A record (and AAAA if you have IPv6):
| Type | Name | Value |
|---|---|---|
| A | n8n.exemple.fr | 203.0.113.10 |
Check propagation:
dig +short n8n.exemple.fr
Step 3: Create the shared Docker network
docker network create web
If you already followed our Caddy reverse proxy tutorial, this network may already exist: ignore the error if there is one.
Step 4: Prepare the folder and the .env file
n8n absolutely needs a persistent encryption key: it encrypts your stored credentials. If it changes, all your saved credentials become unreadable. We generate it once and freeze it in .env.
mkdir -p ~/n8n && cd ~/n8n
nano .env
# --- Domain ---
N8N_HOST=n8n.exemple.fr
N8N_PROTOCOL=https
# Full public webhook URL (with trailing slash, as in the n8n docs)
WEBHOOK_URL=https://n8n.exemple.fr/
# --- Encryption key (NEVER change it after the first start) ---
N8N_ENCRYPTION_KEY=replace_with_the_generated_key
# --- PostgreSQL database ---
POSTGRES_USER=n8n
POSTGRES_PASSWORD=replace_with_a_long_password
POSTGRES_DB=n8n
# --- Misc ---
GENERIC_TIMEZONE=Europe/Paris
TZ=Europe/Paris
Generate the encryption key and a database password:
echo "N8N_ENCRYPTION_KEY : $(openssl rand -hex 24)"
echo "POSTGRES_PASSWORD : $(openssl rand -base64 32)"
Copy these values into .env, then protect the file with chmod 600 .env. Store the encryption key in your password manager: you will need it to restore a backup on another server.
Step 5: The n8n docker-compose.yml
nano docker-compose.yml
services:
postgres:
image: postgres:16-alpine
container_name: n8n_postgres
restart: unless-stopped
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
volumes:
- n8n_pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
interval: 10s
timeout: 5s
retries: 5
networks:
- n8n-internal
n8n:
image: docker.n8n.io/n8nio/n8n:latest
container_name: n8n
restart: unless-stopped
environment:
# --- PostgreSQL connection ---
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}
# --- Domain and webhooks ---
N8N_HOST: ${N8N_HOST}
N8N_PROTOCOL: ${N8N_PROTOCOL}
N8N_PORT: 5678
WEBHOOK_URL: ${WEBHOOK_URL}
N8N_EDITOR_BASE_URL: ${WEBHOOK_URL}
# --- Security ---
N8N_ENCRYPTION_KEY: ${N8N_ENCRYPTION_KEY}
N8N_SECURE_COOKIE: "true"
# Required behind a reverse proxy: trusts the X-Forwarded headers
N8N_PROXY_HOPS: 1
# --- Misc ---
GENERIC_TIMEZONE: ${GENERIC_TIMEZONE}
TZ: ${TZ}
volumes:
- n8n_data:/home/node/.n8n
depends_on:
postgres:
condition: service_healthy
networks:
- web
- n8n-internal
volumes:
n8n_pgdata:
n8n_data:
networks:
web:
external: true
n8n-internal:
The n8n service sits on two networks: n8n-internal to reach PostgreSQL, and web to be reached by Caddy. PostgreSQL is only on the internal network. There is no ports: section: n8n is never exposed directly, unlike examples that publish 5678:5678 on the server’s IP. The N8N_PROXY_HOPS: 1 setting is required behind a reverse proxy; otherwise n8n complains about the X-Forwarded-For header.
Step 6: The Caddyfile for automatic HTTPS
If you already run Caddy, add the site block. Otherwise, create a Caddy folder:
mkdir -p ~/caddy && cd ~/caddy
nano Caddyfile
{
email admin@exemple.fr
}
n8n.exemple.fr {
encode gzip zstd
header {
Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
X-Content-Type-Options "nosniff"
Referrer-Policy "strict-origin-when-cross-origin"
-Server
}
reverse_proxy n8n:5678
}
n8n’s internal port is 5678. Caddy natively handles the WebSockets used by the workflow editor, and obtains and renews the Let’s Encrypt certificate on its own.
Then Caddy’s docker-compose.yml:
nano docker-compose.yml
services:
caddy:
image: caddy:2-alpine
container_name: caddy
restart: unless-stopped
ports:
- "80:80"
- "443:443"
- "443:443/udp"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
networks:
- web
volumes:
caddy_data:
caddy_config:
networks:
web:
external: true
Prefer Traefik or Nginx Proxy Manager? Our Traefik vs Nginx Proxy Manager vs Caddy comparison helps you decide; the principle stays the same.
Step 7: Start the services
cd ~/n8n && docker compose up -d
cd ~/caddy && docker compose up -d
Follow the logs to check the database connection and certificate issuance:
cd ~/n8n && docker compose logs -f n8n
When n8n shows Editor is now accessible via ..., open https://n8n.exemple.fr. The owner account creation screen appears.
Step 8: Create the owner account and a first workflow
- Enter an email and a strong password: this account owns the instance.
- Create a simple first workflow to validate the setup, for example a “Manual” trigger followed by an “HTTP Request” node calling a public API, and run it.
- Test a webhook: create a workflow with a “Webhook” node, activate it, and call the URL it gives you (it correctly uses
https://n8n.exemple.fr/...thanks toWEBHOOK_URL). This is the decisive test: if the webhook answers over HTTPS, your deployment is correct.
Then add your credentials (API keys for the services you automate) through n8n’s credentials manager, never in plain text inside nodes: they are encrypted with your N8N_ENCRYPTION_KEY before being stored in the database.
Step 9: Backups
All of n8n’s useful state lives in PostgreSQL (workflows, encrypted credentials, executions). The encryption key, on the other hand, is in .env and the n8n_data volume. Back up both.
nano ~/n8n/backup.sh
#!/bin/bash
set -euo pipefail
cd "$HOME/n8n"
BACKUP_DIR="$HOME/n8n/backups"
STAMP=$(date +%Y%m%d-%H%M%S)
mkdir -p "$BACKUP_DIR"
# Consistent dump of the PostgreSQL database
docker compose exec -T postgres \
pg_dump -U n8n -d n8n | gzip > "$BACKUP_DIR/n8n-db-$STAMP.sql.gz"
# Back up the .env file (contains the encryption key — protect it!)
cp .env "$BACKUP_DIR/.env-$STAMP"
# Keep 14 days
find "$BACKUP_DIR" -name 'n8n-db-*.sql.gz' -mtime +14 -delete
find "$BACKUP_DIR" -name '.env-*' -mtime +14 -delete
chmod +x ~/n8n/backup.sh
(crontab -l 2>/dev/null; echo "0 3 * * * $HOME/n8n/backup.sh") | crontab -
A database backup without the encryption key is useless: you could restore the workflows, but not decrypt the credentials. Backups left on the same server do not protect you from that server failing: send them off-site and encrypted with our guide to automatic backups with Restic and Backblaze, and test a restore from time to time.
Step 10: Final check
# Containers are running and the database is healthy
docker compose -f ~/n8n/docker-compose.yml ps
# HTTP redirects to HTTPS (code 308)
curl -sI http://n8n.exemple.fr | head -1
# HTTPS responds
curl -sI https://n8n.exemple.fr | head -1
Securing an exposed n8n instance
An automation engine holds the keys to all your connected services (email, CRM, payments): compromising it can mean compromising everything.
- Strict UFW firewall. Open only 80, 443 and SSH. n8n’s port 5678 and PostgreSQL’s 5432 must never be reachable from outside; the network setup above already takes care of that.
- Protected owner account. Strong password and two-factor authentication; if you work as a team, one account per person.
- Protected encryption key. The
.envfile holds the secrets:chmod 600 .envand never commit it. - Public webhooks. Any workflow exposing a webhook is publicly reachable: add authentication (header, token) in the Webhook node.
- Restricted editor, if needed. Caddy can open the interface only to certain addresses (office, VPN) with a
remote_ipmatcher. Keep your workflows’ public URLs reachable: the/webhook/paths and, if you use them, those of n8n forms and Wait nodes.
To harden the system itself (SSH, automatic updates, fail2ban), follow install and secure an Ubuntu VPS.
Updating and monitoring n8n
n8n ships often, and a major version can change how some nodes behave. So don’t update automatically:
- Read the release notes, especially before a major version.
- Run the backup (
~/n8n/backup.sh). - Update:
cd ~/n8n
docker compose pull
docker compose up -d
- Check the logs and rerun a test workflow.
For monitoring, a lightweight tool such as Uptime Kuma, or Prometheus and Grafana, is enough: URL availability, container CPU and RAM, failed executions, and above all disk space, because a workflow stuck in an error loop can fill the disk within days. Our guide to monitoring your homelab with Uptime Kuma and Grafana covers the setup. To troubleshoot, N8N_LOG_LEVEL: debug in the environment section makes the logs more verbose; switch back to info afterwards.
Troubleshooting
- “Mismatching encryption keys” or “Credentials could not be decrypted”. You changed or lost
N8N_ENCRYPTION_KEY. Restore the original key from your backup; otherwise the encrypted credentials cannot be recovered. - Proxy error or insecure cookie.
N8N_PROXY_HOPSorN8N_SECURE_COOKIEis missing. Check these variables and make sureN8N_PROTOCOLis set tohttps. - Webhooks point to
localhostor the IP.WEBHOOK_URLis not set correctly. It must be the full public HTTPS URL. - n8n cannot connect to the database. Check the PostgreSQL credentials and that the
postgresservice ishealthy(docker compose ps). Thedepends_on … condition: service_healthysetting prevents premature starts.
Where to run n8n: VPS or mini PC
Webhooks must be able to reach n8n at any hour: the machine stays on around the clock.
- A VPS is the simplest option when external services (Stripe, GitHub, forms) call your webhooks: a fixed IP address and no port to open on your home router. A small VPS from Hetzner or Infomaniak is enough to start; our Hetzner vs OVH vs Contabo comparison details the plans. If you would rather not handle server maintenance, PlanetHoster offers managed VPS plans, ready in minutes: see PlanetHoster plans.
- A low-power mini PC works if your automations mostly talk to services at home (home automation, NAS) and to keep your data with you. Two common picks: the Beelink Mini S12 Pro (Intel N100, 6 W TDP and up to 16 GB of DDR4 according to its spec sheet) and the Beelink EQ14 (Intel N150, dual 2.5 GbE ports, built-in power supply). To receive webhooks from outside, you will need to forward ports 80 and 443 to the reverse proxy. To choose: our guide to the best mini PCs for a homelab.
FAQ
Is self-hosted n8n really free?
The Community edition is free and has no execution limit: you only pay for your server. It is distributed under the Sustainable Use License, a fair-code license: personal or internal use is free, reselling n8n as a hosted service is restricted. Some features (enterprise SSO, environments, certain collaboration options) belong to a paid Enterprise offer, but the Community edition covers most needs of an individual or a small team.
Why use PostgreSQL instead of the default SQLite database?
SQLite works for testing, but quickly shows its limits with concurrent executions and a large history. PostgreSQL handles load, hot backups and data growth better. For an instance you plan to use seriously, you may as well start with PostgreSQL.
What happens if I lose my encryption key?
Your workflows can still be recovered, but all saved credentials become unreadable: you will have to re-enter them one by one. That is why the key must be stored in your password manager and backed up with the database. Never regenerate it on an existing instance.
Why don’t my webhooks work with external services?
Most often, WEBHOOK_URL does not match the public HTTPS URL, or the domain is not reachable from the Internet. Many services (Stripe, GitHub…) refuse to register a webhook pointing to a bare IP or plain HTTP. The HTTPS reverse proxy in this tutorial solves that.
How do I migrate from n8n Cloud to my own server?
Export your workflows as JSON from n8n Cloud and import them into your instance. Credentials don’t always carry over: plan to recreate them in the local interface. Webhook URLs change with the domain: update the external services (Stripe, Slack…) that call them.
Can I run AI in my n8n workflows?
Yes. n8n includes nodes for LLMs (OpenAI, local models via Ollama, AI agents). Self-hosted, it can call a local model so all data stays with you; see Ollama vs llama.cpp for the engine. Expect much more RAM, and preferably a GPU, on the machine running the model.
Key facts
Our picks
Affiliate links · same price for youBeelink Mini S12 Pro
- Intel N100, 4 cores / 4 threads, 6 W TDP
- DDR4, 16 GB maximum (1 slot)
- 1 M.2 2280 slot and 1 2.5-inch SATA bay
Amazon · price and availability on the listing
Beelink EQ14
- Intel N150, 4 cores / 4 threads
- DDR4 SO-DIMM, 16 GB maximum
- 2 M.2 PCIe 3.0 slots, built-in power supply
Amazon · price and availability on the listing
See all our recommended gear in the shop.