Complete Guide to Self-Hosting n8n in 2025
Step-by-step tutorial for deploying n8n on a VPS, configuring SSL, setting up PostgreSQL, enabling queue mode, and monitoring with Grafana.
Self-hosting n8n gives you complete data sovereignty, no per-execution pricing, and the ability to run unlimited workflows. The tradeoff is infrastructure responsibility — but with Docker and a modern VPS, the setup takes under 2 hours and maintenance is minimal. This is the exact stack we use for client deployments that handle sensitive data.
What You'll Need
- A VPS with at least 2 vCPU / 4GB RAM (we recommend Hetzner CX22 at €5.77/mo, or DigitalOcean Droplet 4GB)
- A domain name pointed at your server's IP
- Ubuntu 22.04 LTS
- Basic Linux CLI familiarity
Step 1: Server Setup
# SSH into your server
ssh root@your-server-ip
# Update packages
apt update && apt upgrade -y
# Install Docker
curl -fsSL https://get.docker.com | sh
systemctl enable docker
# Install Nginx + Certbot
apt install nginx certbot python3-certbot-nginx -y
Step 2: PostgreSQL Database
n8n uses SQLite by default, which is fine for personal use but breaks under concurrent load. For production, use PostgreSQL.
# docker-compose.yml
version: '3.8'
services:
postgres:
image: postgres:16
restart: always
environment:
POSTGRES_DB: n8n
POSTGRES_USER: n8n
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
volumes:
- postgres_data:/var/lib/postgresql/data
n8n:
image: n8nio/n8n:latest
restart: always
ports:
- "5678:5678"
environment:
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_DATABASE=n8n
- DB_POSTGRESDB_USER=n8n
- DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
- N8N_BASIC_AUTH_ACTIVE=true
- N8N_BASIC_AUTH_USER=${N8N_USER}
- N8N_BASIC_AUTH_PASSWORD=${N8N_PASSWORD}
- WEBHOOK_URL=https://n8n.yourdomain.com
- N8N_PROTOCOL=https
- N8N_HOST=n8n.yourdomain.com
- EXECUTIONS_PROCESS=main
- N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
volumes:
- n8n_data:/home/node/.n8n
depends_on:
- postgres
volumes:
postgres_data:
n8n_data:
Step 3: SSL with Nginx
# /etc/nginx/sites-available/n8n
server {
listen 80;
server_name n8n.yourdomain.com;
location / {
proxy_pass http://localhost:5678;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_cache_bypass $http_upgrade;
# Required for n8n websockets
proxy_read_timeout 88400;
send_timeout 88400;
}
}
ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/
certbot --nginx -d n8n.yourdomain.com
systemctl reload nginx
Step 4: Queue Mode for High-Volume Workflows
Queue mode uses Redis to distribute workflow execution across multiple worker processes — essential if you're running more than ~20 concurrent workflows or have long-running jobs.
# Add to docker-compose.yml
redis:
image: redis:7
restart: always
n8n-worker:
image: n8nio/n8n:latest
command: worker
environment:
# Same env vars as n8n, plus:
- EXECUTIONS_PROCESS=worker
- QUEUE_BULL_REDIS_HOST=redis
depends_on:
- redis
- postgres
Set EXECUTIONS_PROCESS=queue on the main n8n instance and worker on worker instances. Scale worker replicas with docker-compose up --scale n8n-worker=3.
Step 5: Monitoring with Grafana
n8n exposes Prometheus metrics at /metrics (enable with N8N_METRICS=true). Key metrics to watch:
n8n_executions_total— total executions by workflow and statusn8n_executions_duration_seconds— p50/p95 execution timen8n_failed_executions_total— alert on spikesnodejs_heap_space_size_used_bytes— memory usage
Add a Prometheus scrape target for your n8n instance and import the community n8n Grafana dashboard (ID: 17556).
Backup Strategy
Daily PostgreSQL dumps to S3-compatible storage:
# /etc/cron.daily/n8n-backup
#!/bin/bash
docker exec postgres pg_dump -U n8n n8n | gzip | aws s3 cp - s3://your-bucket/n8n/backup-$(date +%Y%m%d).sql.gz
Also back up the n8n_data volume which contains credentials and workflow files.
Need help deploying n8n for your team? Book a free audit — we set up and manage n8n infrastructure as part of our automation packages.
Your Competitors Are Already
Automating. Are You?
Book a free 60-minute automation audit and walk away with a custom roadmap showing exactly where your business can save time and money — at no cost, no risk.