How to Install n8n on Hetzner (Complete Production Setup Guide 2025)

By · · 16 min read

Last updated:

How to Install n8n on Hetzner (Complete Production Setup Guide 2025)

Why Self-Host n8n on Hetzner Instead of Paying $50/Month for n8n Cloud?

n8n Cloud costs $20-50/month for limited executions. A Hetzner VPS costs €3.49-5/month and gives you unlimited executions, full data control, and the ability to run any workflow without artificial limits.

The math is simple: n8n Cloud at $50/month = €600/year. Hetzner VPS at €5/month = €60/year. For roughly the same functionality, self-hosting saves you €540 annually — and gives you more control.

This guide gets you from zero to a production-ready n8n instance with SSL, automatic restarts, and PostgreSQL database in about 30 minutes.


What You'll Need

  • A Hetzner Cloud account (create at cloud.hetzner.com — credit card required)
  • A domain name (or subdomain like n8n.yourdomain.com)
  • Basic comfort with terminal/SSH
  • About 30 minutes

Recommended server: CX22 (2 vCPU, 4GB RAM, 40GB SSD, €3.49/month for Linux) — handles most automation workloads comfortably. Upgrade to CX32 if you run very intensive workflows or many concurrent executions.


Step 1: Create Your Hetzner Server

1.1 Log into the Hetzner Cloud Console

Go to console.hetzner.cloud, select your project (or create one), and click + CREATE SERVER.

1.2 Configure the server:

  • Location: Choose the region closest to you or your users. Nuremberg and Falkenstein are the most popular EU options.
  • Image: Select Ubuntu 24.04 LTS (under the OS tab)
  • Type: Select CX22 (Shared CPU, 2 vCPU, 4GB RAM)
  • Networking: Enable both IPv4 and IPv6
  • SSH Keys: Add your SSH public key (strongly recommended over password authentication)
  • Firewall: Create a new firewall allowing ports 22 (SSH), 80 (HTTP), and 443 (HTTPS)
  • Name: Give it a descriptive name like n8n-production

Click CREATE & BUY NOW. Your server will be ready in about 30 seconds.

1.3 Note your server's IP address — you'll need it for DNS setup and SSH access.


Step 2: Configure Your Domain

Go to your domain's DNS settings (wherever you manage your DNS — Cloudflare, Namecheap, etc.) and create an A record:

Type: A
Name: n8n (or @ for root domain)
Value: YOUR_SERVER_IP
TTL: 300

Your n8n instance will be accessible at n8n.yourdomain.com.

Note: DNS propagation can take a few minutes to a few hours. You can proceed with setup while waiting.


Step 3: Initial Server Setup

SSH into your server:

ssh root@YOUR_SERVER_IP

Update the system:

apt update && apt upgrade -y

Install Docker:

curl -fsSL https://get.docker.com | sh

Create a dedicated user for n8n (security best practice — don't run n8n as root):

useradd -m -s /bin/bash n8nuser
usermod -aG docker n8nuser
usermod -aG sudo n8nuser

Create the directory structure:

mkdir -p /opt/n8n/data
mkdir -p /opt/n8n/postgres
chown -R n8nuser:n8nuser /opt/n8n

Switch to the n8n user:

su - n8nuser
cd /opt/n8n

Step 4: Create the Docker Compose File

Create the main configuration file:

nano /opt/n8n/docker-compose.yml

Paste this complete configuration:

version: '3.8'

services:
  postgres:
    image: postgres:16-alpine
    container_name: n8n-postgres
    restart: unless-stopped
    environment:
      POSTGRES_USER: n8n
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: n8n
    volumes:
      - ./postgres:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U n8n"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - n8n-network

  n8n:
    image: n8nio/n8n:latest
    container_name: n8n-app
    restart: unless-stopped
    depends_on:
      postgres:
        condition: service_healthy
    environment:
      - N8N_HOST=${N8N_HOST}
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - NODE_ENV=production
      - WEBHOOK_URL=https://${N8N_HOST}/
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=postgres
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=n8n
      - DB_POSTGRESDB_USER=n8n
      - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
      - N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER=${N8N_BASIC_AUTH_USER}
      - N8N_BASIC_AUTH_PASSWORD=${N8N_BASIC_AUTH_PASSWORD}
      - EXECUTIONS_DATA_PRUNE=true
      - EXECUTIONS_DATA_MAX_AGE=168
    volumes:
      - ./data:/home/node/.n8n
    ports:
      - "5678:5678"
    networks:
      - n8n-network

  caddy:
    image: caddy:2-alpine
    container_name: n8n-caddy
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - caddy_data:/data
      - caddy_config:/config
    networks:
      - n8n-network

networks:
  n8n-network:
    driver: bridge

volumes:
  caddy_data:
  caddy_config:

Save and exit (Ctrl+X, then Y, then Enter).


Step 5: Create the Environment Variables File

nano /opt/n8n/.env

Fill in your values:

# Your domain
N8N_HOST=n8n.yourdomain.com

# Generate strong passwords for these
POSTGRES_PASSWORD=generate-a-strong-password-here
N8N_ENCRYPTION_KEY=generate-a-32-char-random-string

# n8n login credentials
N8N_BASIC_AUTH_USER=your-username
N8N_BASIC_AUTH_PASSWORD=your-secure-password

To generate secure random values:

# Run this twice — once for POSTGRES_PASSWORD, once for N8N_ENCRYPTION_KEY
openssl rand -hex 32

Protect the .env file:

chmod 600 /opt/n8n/.env

Step 6: Create the Caddy Configuration (SSL/Reverse Proxy)

Caddy handles SSL certificates automatically via Let's Encrypt — no manual certificate management needed.

nano /opt/n8n/Caddyfile
n8n.yourdomain.com {
    reverse_proxy n8n:5678 {
        flush_interval -1
    }
}

Replace n8n.yourdomain.com with your actual domain.


Step 7: Start n8n

cd /opt/n8n
docker compose up -d

Check that everything is running:

docker compose ps

You should see three containers running: n8n-postgres, n8n-app, and n8n-caddy.

Watch the startup logs:

docker compose logs -f n8n

First startup takes 2-3 minutes (PostgreSQL initialization). Wait until you see Editor is now accessible via: https://n8n.yourdomain.com.


Step 8: First Login and Security Check

Open your browser and go to https://n8n.yourdomain.com.

You should see an n8n login page. Enter the credentials you set in the .env file.

Important first steps after login:

  1. Change your password if you set a simple one for testing
  2. Go to Settings → Users and verify only your account exists
  3. Go to Settings → Community Nodes to enable additional integrations if needed

Step 9: Set Up Automatic Backups

Your data lives in /opt/n8n/postgres and /opt/n8n/data. Set up daily backups:

nano /opt/n8n/backup.sh
#!/bin/bash
BACKUP_DIR="/opt/n8n/backups"
DATE=$(date +%Y%m%d_%H%M%S)
mkdir -p $BACKUP_DIR

# Backup PostgreSQL database
docker exec n8n-postgres pg_dump -U n8n n8n > $BACKUP_DIR/n8n_db_$DATE.sql

# Backup n8n data directory
tar -czf $BACKUP_DIR/n8n_data_$DATE.tar.gz /opt/n8n/data

# Keep only last 7 days of backups
find $BACKUP_DIR -name "*.sql" -mtime +7 -delete
find $BACKUP_DIR -name "*.tar.gz" -mtime +7 -delete

echo "Backup completed: $DATE"
chmod +x /opt/n8n/backup.sh

# Schedule daily backups at 2am
crontab -e
# Add this line:
0 2 * * * /opt/n8n/backup.sh >> /opt/n8n/backups/backup.log 2>&1

Step 10: Keeping n8n Updated

To update to the latest n8n version:

cd /opt/n8n
docker compose pull n8n
docker compose up -d
docker image prune -f

Run this monthly or when a new n8n version is released that has features you want.


Troubleshooting Common Issues

n8n won't start — check logs:

docker compose logs n8n --tail=50

SSL certificate not issuing: - Verify DNS has propagated: dig n8n.yourdomain.com - Ensure ports 80 and 443 are open in Hetzner's firewall - Wait 5-10 minutes — Let's Encrypt can be slow

PostgreSQL connection error: - Check that the POSTGRES_PASSWORD in .env matches exactly - Run docker compose restart postgres and wait 30 seconds

Webhook not working: - Verify WEBHOOK_URL in the .env exactly matches your domain with https://


Hetzner vs. Hostinger: Which Should You Choose?

Both are excellent for self-hosting n8n. Here's a quick comparison:

FactorHetznerHostinger
PricingFrom €3.49/monthFrom $4/month
Data center locationEU (Germany, Finland)EU, US, Asia
Performance (price/performance)ExcellentGood
Docker supportYesYes
GDPR complianceVery strong (German data centers)Good
SupportGoodVery good
Best forTechnical users, EU complianceBeginners, global coverage

Recommendation: - Choose Hetzner if you're in Europe, care about data sovereignty, or want the best price/performance ratio - Choose Hostinger if you need 24/7 live chat support and a more beginner-friendly interface

The setup process is identical for both — just replace "Hetzner" with your chosen provider.


What to Build Now That n8n Is Running

With your self-hosted n8n instance ready, some high-value automation workflows to build:

  • Lead qualification pipeline: New CRM contact → AI scoring → Slack notification with summary
  • Content calendar: Google Sheets trigger → AI content generation → Postiz scheduling
  • Customer support routing: Email → AI classification → Assign to right team member
  • Sales intelligence: Webhook from website form → Clay enrichment → CRM creation → Slack alert
  • Daily briefing: Cron at 7am → Pull news + calendar + tasks → AI summary → Telegram message

Part of The Lazy Leader series on building automation infrastructure. Subscribe for workflow templates and self-hosting guides.