You run n8n self hosted by starting n8n with Docker Compose on your own server. The setup includes a PostgreSQL database, a reverse proxy for HTTPS and a fixed key for your credentials. With this guide, the installation takes about one hour.
This guide is for team leads and technically minded managing directors in small and mid-sized companies. You need basic command-line knowledge. You do not need programming skills.
Is n8n self hosted worth it for your company?
Self-hosting is worth it if your data must stay in your own data centre or with an EU hosting provider. It is also worth it at high volumes, because the Community Edition has no execution limit. You only pay for the server.
The Community Edition uses the Sustainable Use License. The license allows use "for your own internal business purposes". So you can run n8n for your own processes. You cannot resell n8n as a paid service to third parties. Some features are in files with the extension .ee and need an Enterprise license.
| Criterion | n8n Cloud | n8n self hosted |
|---|---|---|
| Setup | Minutes | approx. 1 hour |
| Data location | n8n's servers | Your chosen server |
| Executions | Limit per plan | No limit |
| Updates and backups | n8n does them | You do them |
| Running costs | Plan price | Server plus your time |
If you are new to n8n, start with the n8n tutorial for beginners.
Step 1: Choose the server
Choose a Linux server in an EU data centre. For small to medium loads, 2 vCPU, 4 GB RAM and a 40 GB SSD are enough. This is the smallest useful size for n8n with PostgreSQL.
One example is Hetzner, with data centres in Nuremberg, Falkenstein and Helsinki. The CX23 plan has exactly this size. According to the price list, it costs €5.99 per month excluding VAT (as of November 2026). In November 2026, Hetzner showed the Cost-Optimized plans as "not available". In that case, choose another plan with the same size.
Check these points when you choose:
- Choose Ubuntu 24.04 LTS as the operating system.
- Add an SSH key instead of a password when you create the server.
- Sign a data processing agreement (DPA) with the hosting provider.
- Create a subdomain, for example
n8n.your-company.com. Replace it with your own domain in all files below. - Point the DNS record (type A) to the IP address of the server.
The DPA defines how the hosting provider processes personal data on your behalf. The GDPR requires it as soon as workflows process customer data. For a data-protection comparison of the tools, read the article Zapier alternatives 2026.
Step 2: Install Docker and Docker Compose
Docker runs programs in containers (closed packages with everything a program needs). Docker Compose starts several containers together from one file. The official Docker installation script includes both.
- Log in to the server via SSH.
- Update the system.
- Install Docker with the official script.
- Check the versions.
ssh root@YOUR-SERVER-IP
apt update && apt upgrade -y
curl -fsSL https://get.docker.com | sh
docker --version
docker compose version
If docker compose version shows a version number, Compose is ready. Use the command docker compose with a space. You do not need the old program docker-compose with a hyphen.
Step 3: Create the docker-compose.yml
The file docker-compose.yml describes three containers: Caddy, PostgreSQL and n8n. Caddy is a reverse proxy (a program that accepts requests from the internet and passes them to n8n). Caddy gets the HTTPS certificate from Let's Encrypt and renews it automatically.
First, create a folder:
mkdir -p /opt/n8n && cd /opt/n8n
Then create the file docker-compose.yml with this content:
services:
caddy:
image: caddy:2
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
depends_on:
- n8n
postgres:
image: postgres:16
restart: unless-stopped
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
interval: 10s
timeout: 5s
retries: 5
n8n:
image: n8nio/n8n:2.48.7
restart: unless-stopped
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_HOST: ${N8N_DOMAIN}
N8N_PORT: 5678
N8N_PROTOCOL: https
N8N_WEBHOOK_URL: https://${N8N_DOMAIN}/
N8N_PROXY_HOPS: 1
N8N_ENCRYPTION_KEY: ${N8N_ENCRYPTION_KEY}
GENERIC_TIMEZONE: Europe/Berlin
TZ: Europe/Berlin
NODE_ENV: production
N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS: "true"
volumes:
- n8n_data:/home/node/.n8n
depends_on:
postgres:
condition: service_healthy
volumes:
caddy_data:
caddy_config:
postgres_data:
n8n_data:
Note three details in this file:
- The n8n container has no
portsentry. So port 5678 is not reachable from outside. Only Caddy talks to n8n in the internal Docker network. - The image has a fixed version number. Version 2.48.7 was the current stable version in November 2026. Check the current number in the n8n release notes.
- PostgreSQL stays on version 16. A jump to a new major version needs a separate database migration.
Step 4: Environment variables and Caddyfile
Environment variables (settings that a container reads at start) go into a file .env in the same folder. Docker Compose reads this file automatically. This keeps passwords out of the docker-compose.yml.
First, generate two random values:
openssl rand -hex 32 # for N8N_ENCRYPTION_KEY
openssl rand -hex 24 # for POSTGRES_PASSWORD
Then create the file .env:
N8N_DOMAIN=n8n.your-company.com
N8N_ENCRYPTION_KEY=paste-first-random-value-here
POSTGRES_USER=n8n
POSTGRES_PASSWORD=paste-second-random-value-here
POSTGRES_DB=n8n
Put the first random value into N8N_ENCRYPTION_KEY and the second into POSTGRES_PASSWORD. Protect the file with chmod 600 .env. Then only the root user can read it.
These variables control how n8n behaves:
| Variable | Effect |
|---|---|
N8N_HOST | Domain where n8n runs |
N8N_PROTOCOL | https, because Caddy encrypts |
N8N_WEBHOOK_URL | Public address for webhooks |
N8N_ENCRYPTION_KEY | Key for stored credentials |
N8N_PROXY_HOPS | Number of proxies in front of n8n, here 1 |
GENERIC_TIMEZONE | Time zone for Schedule triggers |
TZ | System time zone in the container |
A webhook is an address that receives data from another system. Without N8N_WEBHOOK_URL, n8n shows webhook addresses with localhost. External services cannot reach these addresses. If your n8n version is older than 2.30, the variable is called WEBHOOK_URL. From version 2.35, WEBHOOK_URL is deprecated but still works. The webhook guide shows how webhooks work in detail.
Finally, create the file Caddyfile. Two lines are enough:
n8n.your-company.com {
reverse_proxy n8n:5678
}
Now start all containers:
docker compose up -d
docker compose logs -f n8n
When the log shows Editor is now accessible via, n8n is ready. Open https://n8n.your-company.com in your browser. Create the owner account immediately. Until you do, anyone with the address can create this account.
Step 5: Secure the server
An n8n server holds the credentials for your CRM, accounting and mailboxes. So secure it before the first production workflow.
- Allow only ports 22, 80 and 443 in a firewall.
- Turn off SSH login with a password.
- Turn on automatic security updates with
unattended-upgrades. - Turn on two-factor login for all n8n accounts.
- Give each employee their own n8n account instead of a shared login.
apt install -y ufw unattended-upgrades
ufw allow OpenSSH
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable
The cloud firewall of your hosting provider adds a second layer of protection. It filters traffic before it reaches the server. At Hetzner, it is called "Firewalls" in the Cloud Console. The article AI agent permissions and security describes which permissions AI agents in workflows should get.
Step 6: Set up backups
A complete backup has two parts: the database dump and the N8N_ENCRYPTION_KEY. The database contains workflows, credentials and executions. Without the key, the credentials in the backup cannot be read.
Create a script /opt/n8n/backup.sh:
#!/bin/sh
cd /opt/n8n
mkdir -p backups
docker compose exec -T postgres pg_dump -U n8n -d n8n | gzip > backups/n8n-$(date +%F).sql.gz
find backups -name "*.sql.gz" -mtime +14 -delete
Make the script executable and add it to cron (the Linux scheduler). The entry below runs the backup every day at 3 a.m.:
chmod +x /opt/n8n/backup.sh
crontab -e
# Entry: every day at 3 a.m.
0 3 * * * /opt/n8n/backup.sh
A backup on the same server does not protect you if the server fails. So copy the files to a second location every night. This can be a storage service at a different provider, for example with rsync or restic. Test the restore once per quarter on a test server. A backup that nobody has ever restored is only a hope.
Step 7: Update n8n safely
An update changes the version number of the image and restarts the container. Your data stays in the volumes. Follow this order:
- Read the release notes of the new version.
- Run the backup script by hand.
- Change the version number in the
docker-compose.yml. - Pull the new image and restart.
- Check in the log that the database migration ends without errors.
- Test two or three important workflows by hand.
cd /opt/n8n
./backup.sh
docker compose pull
docker compose up -d
docker compose logs -f n8n
When a new major version comes out, read the n8n migration guide first. For example, the settings for task runners changed in the jump from 1.x to 2.x. Update in small steps every month rather than in one large jump once a year.
To notice an outage early, set up monitoring from outside. Uptime monitoring automation shows how.
Common errors and how to fix them
Most errors with n8n self hosted come from missing variables or wrong ports. This table shows the most common cases:
| Symptom | Cause | Fix |
|---|---|---|
Webhook address shows localhost | N8N_WEBHOOK_URL is missing | Set the variable, restart |
| "Mismatching encryption keys" | Key changed or lost | Enter the old key from the password manager |
| No HTTPS certificate | DNS does not point to the server yet | Check DNS, read the Caddy log |
Warning about X-Forwarded-For | N8N_PROXY_HOPS is missing | Set the value 1 |
| Schedule runs one hour off | Time zone is missing | Set GENERIC_TIMEZONE and TZ |
| n8n starts before the database | No healthcheck | Use condition: service_healthy |
If Caddy gets no certificate, read docker compose logs caddy first. Usually port 80 is closed, or the DNS record has not spread worldwide yet. In that case, wait a few minutes and restart Caddy.
Run it yourself or have it run for you?
With this guide, you can do the installation yourself. Operation needs a few hours every month for updates, backup tests and log checks. If your team does not have this time, consider the cloud version or a service provider. The article n8n implementation services lists the questions you should ask a provider.
Before you spend time on servers, decide which process to automate first. The free self-check has 13 questions and takes about 5 minutes. The short result shows you right away where work gets stuck in your team.
Frequently Asked Questions
Is n8n self hosted free?
The Community Edition has no license fee. You pay for the server and for your time to operate it. The license allows use for internal business purposes. Features marked as Enterprise need a paid license.
Do I need PostgreSQL, or is SQLite enough?
SQLite, the default database of n8n, is enough for tests. For production use, we recommend PostgreSQL. PostgreSQL handles more parallel executions, and you can back it up cleanly with pg_dump.
Why Caddy and not Traefik or Nginx?
Caddy needs only two lines of configuration for HTTPS and renews certificates automatically. The official n8n guide uses Traefik. Traefik works just as well but needs more configuration. Nginx also needs a tool such as Certbot for the certificates.
How much server does n8n need?
For a team with a few dozen workflows, 2 vCPU and 4 GB RAM are enough. If workflows process large files or many parallel executions, choose 4 vCPU and 8 GB RAM. Watch the load in the first weeks with docker stats.
Can I move from n8n Cloud to self hosted?
Yes. Export the workflows as JSON files and import them into your new instance. The export does not include credentials. You create them again in the new instance.
Is n8n self hosted GDPR compliant?
The software alone does not make anything GDPR compliant. What matters is the server location, the DPA with the hosting provider and the services your workflows call. If a workflow sends data to a US service, that service's terms apply. For an overview of the tool choice, read the n8n vs. Make comparison.