🗺️ The Ultimate AI Automation Roadmap — Part 1 of 20 | Tier: Foundations | Difficulty: Beginner | Est. read: 18 min
Part 1: How to Self-Host n8n on a VPS — The Complete 2026 Cloud Automation Setup Guide
Search Intent: You’ve heard about n8n — the open-source automation powerhouse — but every tutorial sends you to n8n.cloud with a $20/month bill. What if you could run the exact same software on your own server for $5–$6/month, own 100% of your data, and scale to unlimited workflows? That’s exactly what this guide delivers. We’re building the foundation of your entire automation infrastructure from scratch.
📋 Table of Components
| Component | Tool/Service | Cost | Purpose |
|---|---|---|---|
| Cloud VPS | Hetzner CX21 or DigitalOcean Droplet | $5–6/mo | Run n8n 24/7 |
| OS | Ubuntu 22.04 LTS | Free | Server OS |
| Containerization | Docker + Docker Compose | Free | Run n8n in isolation |
| Reverse Proxy | Nginx | Free | Route traffic to n8n |
| SSL Certificate | Let’s Encrypt (Certbot) | Free | HTTPS security |
| Domain | Any registrar (Namecheap, Cloudflare) | $10–15/yr | Custom URL for n8n |
| Database | PostgreSQL (via Docker) | Free | Persistent workflow storage |
🌍 Real-World Business Scenario: The Automation Agency Foundation
Imagine you’re building an automation agency serving 15 clients. Each client has 3–5 active workflows running 24/7. On n8n.cloud, that’s $50–$200/month per client workspace. By self-hosting on a $6/month Hetzner VPS, you serve all 15 clients on one server, pocket the difference as pure profit, and maintain complete data sovereignty — critical for clients in healthcare, legal, and finance who can’t let their data leave their infrastructure.
⚙️ Step 1: Provision Your VPS
1.1 — Choose Your Provider
Hetzner (Best Value — EU): CX21 plan — 2 vCPU, 4GB RAM, 40GB SSD — €3.85/month (~$4.20). Handles 20+ concurrent workflows easily. DigitalOcean (Best UX — Global): Basic Droplet — 1 vCPU, 2GB RAM — $6/month. Great for beginners due to excellent documentation. Vultr/Linode: Similar specs at similar pricing. All support one-click Ubuntu 22.04 LTS deployment.
1.2 — Initial Server Setup
After provisioning, SSH into your server and run these hardening commands:
# Connect to your server
ssh root@YOUR_SERVER_IP
# Update system packages
apt update && apt upgrade -y
# Create a non-root user for security
adduser automation
usermod -aG sudo automation
# Set up SSH key authentication (run this on your LOCAL machine)
ssh-copy-id automation@YOUR_SERVER_IP
# Disable root SSH login
sed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
systemctl restart sshd
# Set up UFW firewall
ufw allow OpenSSH
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable
⚙️ Step 2: Install Docker and Docker Compose
# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
# Add user to docker group (no sudo needed)
usermod -aG docker automation
# Install Docker Compose plugin
apt install docker-compose-plugin -y
# Verify installation
docker --version # Docker 24.x.x
docker compose version # Docker Compose 2.x.x
⚙️ Step 3: Deploy n8n with Docker Compose
Create your project directory and Docker Compose file:
mkdir -p /home/automation/n8n && cd /home/automation/n8n
Create docker-compose.yml:
version: "3.8"
services:
postgres:
image: postgres:15
restart: always
environment:
POSTGRES_USER: n8n_user
POSTGRES_PASSWORD: YOUR_STRONG_PASSWORD
POSTGRES_DB: n8n_db
volumes:
- postgres_data:/var/lib/postgresql/data
n8n:
image: docker.n8n.io/n8nio/n8n:latest
restart: always
ports:
- "127.0.0.1:5678:5678"
environment:
- N8N_HOST=n8n.yourdomain.com
- N8N_PORT=5678
- N8N_PROTOCOL=https
- WEBHOOK_URL=https://n8n.yourdomain.com/
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_USER=n8n_user
- DB_POSTGRESDB_PASSWORD=YOUR_STRONG_PASSWORD
- DB_POSTGRESDB_DATABASE=n8n_db
- N8N_ENCRYPTION_KEY=GENERATE_32_CHAR_RANDOM_KEY
- EXECUTIONS_DATA_PRUNE=true
- EXECUTIONS_DATA_MAX_AGE=336
- N8N_METRICS=true
volumes:
- n8n_data:/home/node/.n8n
depends_on:
- postgres
volumes:
postgres_data:
n8n_data:
⚙️ Step 4: Configure Nginx Reverse Proxy + SSL
apt install nginx certbot python3-certbot-nginx -y
# Create Nginx config
cat > /etc/nginx/sites-available/n8n << 'EOF'
server {
server_name n8n.yourdomain.com;
location / {
proxy_pass http://127.0.0.1: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_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 300s;
chunked_transfer_encoding off;
}
}
EOF
ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/
nginx -t && systemctl reload nginx
# Get free SSL certificate
certbot --nginx -d n8n.yourdomain.com --non-interactive --agree-tos -m admin@yourdomain.com
⚙️ Step 5: Launch n8n and Secure It
cd /home/automation/n8n
docker compose up -d
# Verify both containers running
docker compose ps
# View logs
docker compose logs -f n8n
Visit https://n8n.yourdomain.com. You'll see the n8n setup screen. Create your owner account. Your self-hosted, SSL-secured, PostgreSQL-backed n8n instance is live!
🔐 Step 6: Enterprise Security Hardening
- Enable Basic Auth: Add
N8N_BASIC_AUTH_ACTIVE=true,N8N_BASIC_AUTH_USER,N8N_BASIC_AUTH_PASSWORDto your Docker Compose env vars - Rate Limiting: Add
limit_req_zoneto Nginx config to prevent brute-force attacks - Daily Backups: Add a cron job:
0 2 * * * docker exec n8n_postgres pg_dump n8n_db > /backups/n8n_$(date +%Y%m%d).sql - Fail2Ban: Install and configure to auto-ban IPs with failed login attempts
- Watchtower: Add Watchtower container to auto-update n8n to latest version nightly
🔁 Automation Logic: Trigger → Action → Filter → Output
| Stage | What Happens | n8n Node |
|---|---|---|
| 🟢 Trigger | New webhook request hits n8n | Webhook Node |
| ⚡ Action | n8n processes the data | Set / Code Node |
| 🔍 Filter | Check if data meets conditions | IF Node |
| 📤 Output | Send to destination app | HTTP Request / Gmail / Sheets |
📊 Cost Comparison: Self-Hosted vs. Cloud
| Metric | n8n Cloud (Starter) | Self-Hosted VPS | Savings |
|---|---|---|---|
| Monthly cost | $20/mo | $5–6/mo | 70% cheaper |
| Workflow limit | 5 active | Unlimited | ∞ |
| Execution limit | 2,500/mo | Unlimited | ∞ |
| Data ownership | n8n servers | Your server | 100% private |
| Custom packages | ❌ No | ✅ Yes (npm) | Flexibility |
🚀 Next: Part 2
With your VPS running, Part 2 covers Docker fundamentals and how to manage multiple automation services (n8n + Redis + custom Python scripts) on one server using Docker networks and Portainer — the GUI for Docker management.