How to Install n8n on Hetzner: Production Setup Guide
Guide to self-hosting n8n on a Hetzner VPS with Docker, Caddy SSL, PostgreSQL, backups, and updates. Covers setup, security, and troubleshooting.
Automation tools can get expensive once you use them every day. n8n Cloud at $50 per month adds up to €600 a year. This guide shows you how to run n8n on your own Hetzner server with SSL, automatic restarts, and a PostgreSQL database.
In short: You can run a production n8n instance on a Hetzner VPS for about €3.49 to €5 per month, based on the prices in this guide. The setup uses Docker, PostgreSQL, and Caddy for SSL. It takes about 30 minutes from start to finish.
Key takeaways
- n8n Cloud costs $20-50/month for limited executions, while a Hetzner VPS costs €3.49-5/month.
- The recommended server is the CX22, with 2 vCPU, 4GB RAM, and 40GB SSD for €3.49/month for Linux.
- The setup uses Ubuntu 24.04 LTS, Docker, PostgreSQL 16, and Caddy for SSL.
- Caddy handles SSL certificates automatically through Let's Encrypt.
- Ports 22, 80, and 443 need to be open in the firewall.
- Updating n8n takes three commands and should be done monthly or when a new version has features you want.
Why self-host n8n on Hetzner instead of paying $50/month for n8n Cloud?
Self-hosting n8n on Hetzner costs much less than n8n Cloud. 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. n8n Cloud costs $20-50/month for limited executions.
The math is simple. n8n Cloud at $50/month equals €600/year. A Hetzner VPS at €5/month equals €60/year. For roughly the same functionality, self-hosting saves €540 a year and gives you more control.
This guide takes you from zero to a production-ready n8n instance with SSL, automatic restarts, and a PostgreSQL database in about 30 minutes.
What do you need before you start?
You need a Hetzner Cloud account, a domain name, basic comfort with the terminal and SSH, and about 30 minutes. The recommended server is the CX22.
- A Hetzner Cloud account (create at cloud.hetzner.com, credit card required)
- A domain name (or a subdomain like n8n.yourdomain.com)
- Basic comfort with terminal and SSH
- About 30 minutes
Recommended server: CX22 (2 vCPU, 4GB RAM, 40GB SSD, €3.49/month for Linux). It handles most automation workloads comfortably. Upgrade to CX32 if you run very intensive workflows or many concurrent executions.
How do you create your Hetzner server?
You create the server in the Hetzner Cloud Console and set the location, image, type, networking, SSH key, firewall, and name. The server is ready in about 30 seconds after you click create.
- Log into the Hetzner Cloud Console. Go to console.hetzner.cloud, select your project (or create one), and click + CREATE SERVER.
- 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. This is 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.
- Note your server's IP address. You will need it for DNS setup and SSH access.
How do you point your domain to the server?
You point your domain to the server by creating an A record in your DNS settings. Use your server's IP address as the value. DNS can take a few minutes to a few hours to update, so you can keep setting up while you wait.
Go to your domain's DNS settings (wherever you manage DNS, such as Cloudflare, Namecheap, or others) 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.
How do you prepare the server and install Docker?
You connect over SSH, update the system, install Docker, create a dedicated user for n8n, and set up the project folders. Running n8n as a separate user is a security best practice.
- 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. This is a security best practice, so do not 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
What goes in the Docker Compose file?
The Docker Compose file defines three containers: PostgreSQL, n8n, and Caddy. You create it at /opt/n8n/docker-compose.yml and paste the full configuration below.
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 with Ctrl+X, then Y, then Enter.
How do you set the environment variables?
You set the environment variables in a .env file in /opt/n8n. The file holds your domain, your database password, your encryption key, and your n8n login details. Then you lock down the file permissions.
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 and once for N8N_ENCRYPTION_KEY:
openssl rand -hex 32
Protect the .env file:
chmod 600 /opt/n8n/.env
How do you set up Caddy for SSL?
You set up SSL by creating a Caddyfile that sends traffic from your domain to n8n. Caddy gets the certificates for you through Let's Encrypt, so you do not need to manage certificates by hand.
Caddy handles SSL certificates automatically via Let's Encrypt. No manual certificate management is needed.
nano /opt/n8n/Caddyfile
n8n.yourdomain.com {
reverse_proxy n8n:5678 {
flush_interval -1
}
}
Replace n8n.yourdomain.com with your actual domain.
How do you start n8n?
You start n8n by running docker compose up -d from the /opt/n8n folder. The first startup takes 2 to 3 minutes because PostgreSQL has to initialize.
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
The first startup takes 2-3 minutes (PostgreSQL initialization). Wait until you see Editor is now accessible via: https://n8n.yourdomain.com.
How do you log in and run a security check?
You log in at your n8n domain using the credentials you set in the .env file. After that, change your password if it was simple, check that only your account exists, and set up community nodes if you need them.
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:
- Change your password if you set a simple one for testing.
- Go to Settings → Users and verify only your account exists.
- Go to Settings → Community Nodes to enable additional integrations if needed.
How do you set up automatic backups?
You set up automatic backups with a shell script that dumps the PostgreSQL database and archives the n8n data folder. Then you schedule the script with cron to run every day at 2am. Your data lives in /opt/n8n/postgres and /opt/n8n/data.
Create the backup script:
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"
Make the script executable and schedule it:
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
How do you update n8n?
You update n8n by pulling the latest image, restarting the containers, and removing old images. Run these commands monthly, or when a new n8n version has features you want.
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.
How do you troubleshoot common n8n issues?
Start with the logs. Most problems fall into three groups: n8n will not start, SSL is not issuing, or PostgreSQL will not connect. Each group has a simple first check.
n8n won't start. Check the 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 postgresand 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 providers work well for self-hosting n8n. Choose Hetzner for European hosting, data sovereignty, or the best price to performance ratio. Choose Hostinger if you need 24/7 live chat support and a more beginner-friendly interface.
| Factor | Hetzner | Hostinger |
|---|---|---|
| Pricing | From €3.49/month | From $4/month |
| Data center location | EU (Germany, Finland) | EU, US, Asia |
| Performance (price/performance) | Excellent | Good |
| Docker support | Yes | Yes |
| GDP |
Questions people ask
How much does it cost to self-host n8n on Hetzner?
A Hetzner VPS costs €3.49 to €5 per month, according to this guide. The recommended CX22 server is €3.49 per month for Linux. n8n Cloud is listed at $20 to $50 per month for limited executions.
Which Hetzner server should I choose for n8n?
The guide recommends the CX22 server, which has 2 vCPU, 4GB RAM, and 40GB SSD. It says this handles most automation workloads comfortably. Upgrade to CX32 if you run very intensive workflows or many concurrent executions.
How does n8n get an SSL certificate in this setup?
The setup uses Caddy as a reverse proxy. Caddy handles SSL certificates automatically through Let's Encrypt, so you do not need to manage certificates by hand.
How do I update n8n when a new version comes out?
Go to the /opt/n8n folder, then run docker compose pull n8n, docker compose up -d, and docker image prune -f. The guide suggests running this monthly or when a new n8n version has features you want.
What should I do if SSL certificates are not issuing?
First, check that DNS has propagated using dig on your domain. Make sure ports 80 and 443 are open in the Hetzner firewall. Then wait 5 to 10 minutes, since Let's Encrypt can be slow.
