Skip to main content

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

  1. Open https://n8n.yourdomain.com
  2. Create your admin account
  3. Set up your first workflow

Step 6: Essential Configuration

Environment variables to consider:

VariablePurposeExample
N8N_ENCRYPTION_KEYEncrypts credentialsRandom 64-char hex
N8N_USER_MANAGEMENT_DISABLEDSingle user modetrue
EXECUTIONS_DATA_PRUNEAuto-delete old executionstrue
EXECUTIONS_DATA_MAX_AGEExecution retention168 (7 days)
N8N_METRICSEnable Prometheus metricstrue
N8N_DIAGNOSTICS_ENABLEDDisable telemetryfalse
N8N_TEMPLATES_ENABLEDShow workflow templatestrue

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

Slack notification on form submission:

  1. Webhook Trigger → receives form data
  2. Set node → format message
  3. Slack node → post to channel

Daily database backup to S3:

  1. Cron Trigger → runs daily
  2. Execute Command → pg_dump
  3. AWS S3 → upload backup file

GitHub PR → Linear ticket:

  1. GitHub Trigger → on PR opened
  2. Set node → map fields
  3. 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

WorkflowsRAMCPUDisk
1-201 GB1 core10 GB
20-1002 GB2 cores20 GB
100+4 GB4 cores50 GB

VPS Recommendations

ProviderSpecPrice
Hetzner2 vCPU, 4 GB RAM€4.50/month
DigitalOcean1 vCPU, 2 GB RAM$12/month
Linode1 vCPU, 2 GB RAM$12/month

Compare automation platforms on OSSAlt — integrations, pricing, and self-hosting options side by side.