Self-Hosting Guide: Deploy n8n for Workflow Automation
·OSSAlt Team
n8nautomationself-hostingdockerguide
Self-Hosting Guide: Deploy n8n for Workflow Automation
n8n is the open source Zapier alternative with 400+ integrations and a visual workflow builder. Self-hosting gives you unlimited workflows, no execution limits, and full control over your automation data.
Requirements
- VPS with 1 GB RAM minimum (2 GB recommended)
- Docker and Docker Compose
- Domain name (e.g.,
n8n.yourdomain.com) - 10+ GB disk
Step 1: Create Docker Compose
# docker-compose.yml
services:
n8n:
image: n8nio/n8n:latest
container_name: n8n
restart: unless-stopped
ports:
- "5678:5678"
volumes:
- n8n_data:/home/node/.n8n
environment:
- N8N_HOST=n8n.yourdomain.com
- N8N_PORT=5678
- N8N_PROTOCOL=https
- WEBHOOK_URL=https://n8n.yourdomain.com/
- N8N_ENCRYPTION_KEY=your-random-encryption-key
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=db
- DB_POSTGRESDB_PORT=5432
- DB_POSTGRESDB_DATABASE=n8n
- DB_POSTGRESDB_USER=n8n
- DB_POSTGRESDB_PASSWORD=your-strong-password
- GENERIC_TIMEZONE=America/New_York
depends_on:
- db
db:
image: postgres:16-alpine
container_name: n8n-db
restart: unless-stopped
volumes:
- db_data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=n8n
- POSTGRES_USER=n8n
- POSTGRES_PASSWORD=your-strong-password
volumes:
n8n_data:
db_data:
Step 2: Generate Encryption Key
# Generate a random encryption key (keep this safe!)
openssl rand -hex 32
Replace your-random-encryption-key in the compose file. This encrypts all stored credentials. If you lose this key, all saved credentials become unreadable.
Step 3: Start n8n
docker compose up -d
Step 4: Reverse Proxy (Caddy)
# /etc/caddy/Caddyfile
n8n.yourdomain.com {
reverse_proxy localhost:5678
}
sudo systemctl restart caddy
Step 5: Initial Setup
- Open
https://n8n.yourdomain.com - Create your admin account
- Set up your first workflow
Step 6: Essential Configuration
Environment variables to consider:
| Variable | Purpose | Example |
|---|---|---|
N8N_ENCRYPTION_KEY | Encrypts credentials | Random 64-char hex |
N8N_USER_MANAGEMENT_DISABLED | Single user mode | true |
EXECUTIONS_DATA_PRUNE | Auto-delete old executions | true |
EXECUTIONS_DATA_MAX_AGE | Execution retention | 168 (7 days) |
N8N_METRICS | Enable Prometheus metrics | true |
N8N_DIAGNOSTICS_ENABLED | Disable telemetry | false |
N8N_TEMPLATES_ENABLED | Show workflow templates | true |
Step 7: Set Up SMTP (For Email Nodes)
Add to your environment:
N8N_EMAIL_MODE=smtp
N8N_SMTP_HOST=smtp.resend.com
N8N_SMTP_PORT=587
N8N_SMTP_USER=resend
N8N_SMTP_PASS=re_your_api_key
N8N_SMTP_SENDER=n8n@yourdomain.com
N8N_SMTP_SSL=true
Step 8: Popular Workflow Examples
Slack notification on form submission:
- Webhook Trigger → receives form data
- Set node → format message
- Slack node → post to channel
Daily database backup to S3:
- Cron Trigger → runs daily
- Execute Command →
pg_dump - AWS S3 → upload backup file
GitHub PR → Linear ticket:
- GitHub Trigger → on PR opened
- Set node → map fields
- Linear → create issue
Production Hardening
Execution pruning (prevent disk filling up):
EXECUTIONS_DATA_PRUNE=true
EXECUTIONS_DATA_MAX_AGE=168
EXECUTIONS_DATA_PRUNE_MAX_COUNT=10000
Backups:
# Database backup (daily cron)
docker exec n8n-db pg_dump -U n8n n8n > /backups/n8n-$(date +%Y%m%d).sql
# Credentials and workflows
docker cp n8n:/home/node/.n8n /backups/n8n-data-$(date +%Y%m%d)
Updates:
docker compose pull
docker compose up -d
Monitoring:
- Monitor port 5678 with Uptime Kuma
- Enable Prometheus metrics for workflow monitoring
- Set up alerts for failed executions
Resource Usage
| Workflows | RAM | CPU | Disk |
|---|---|---|---|
| 1-20 | 1 GB | 1 core | 10 GB |
| 20-100 | 2 GB | 2 cores | 20 GB |
| 100+ | 4 GB | 4 cores | 50 GB |
VPS Recommendations
| Provider | Spec | Price |
|---|---|---|
| Hetzner | 2 vCPU, 4 GB RAM | €4.50/month |
| DigitalOcean | 1 vCPU, 2 GB RAM | $12/month |
| Linode | 1 vCPU, 2 GB RAM | $12/month |
Compare automation platforms on OSSAlt — integrations, pricing, and self-hosting options side by side.