n8n Workflow Automation
Deploy and configure n8n, a self-hosted workflow automation platform alternative to Zapier with visual workflow builder
What is n8n?
n8n is a self-hosted workflow automation platform and visual workflow builder. It's an open-source alternative to Zapier that allows you to automate business processes by connecting applications and services without writing code. n8n gives you complete control over your data and workflows, making it ideal for hosting providers and enterprises.
Installation with Docker Compose
Simple Setup with SQLite
Create a docker-compose.yml for basic deployments:
version: '3.8'
services:
n8n:
image: n8n:latest
container_name: n8n
restart: unless-stopped
ports:
- "5678:5678"
environment:
- N8N_HOST=n8n.example.com
- N8N_PORT=5678
- N8N_PROTOCOL=https
- WEBHOOK_URL=https://n8n.example.com
- N8N_BASIC_AUTH_ACTIVE=true
- N8N_BASIC_AUTH_USER=admin
- N8N_BASIC_AUTH_PASSWORD=changeme123!
- TZ=UTC
volumes:
- n8n_data:/home/node/.n8n
networks:
- delux_network
volumes:
n8n_data:
driver: local
networks:
delux_network:
external: trueDeploy with:
docker-compose up -dProduction Setup with PostgreSQL
For production environments, use PostgreSQL for better reliability:
version: '3.8'
services:
postgres:
image: postgres:16-alpine
container_name: n8n_db
restart: unless-stopped
environment:
- POSTGRES_DB=n8n
- POSTGRES_USER=n8n
- POSTGRES_PASSWORD=securedbpass123!
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
- delux_network
healthcheck:
test: ["CMD-SHELL", "pg_isready -U n8n"]
interval: 10s
timeout: 5s
retries: 5
n8n:
image: n8n:latest
container_name: n8n
restart: unless-stopped
ports:
- "5678:5678"
environment:
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_PORT=5432
- DB_POSTGRESDB_DATABASE=n8n
- DB_POSTGRESDB_USER=n8n
- DB_POSTGRESDB_PASSWORD=securedbpass123!
- N8N_HOST=n8n.example.com
- N8N_PORT=5678
- N8N_PROTOCOL=https
- WEBHOOK_URL=https://n8n.example.com
- N8N_BASIC_AUTH_ACTIVE=true
- N8N_BASIC_AUTH_USER=admin
- N8N_BASIC_AUTH_PASSWORD=changeme123!
- N8N_ENCRYPTION_KEY=your-secure-encryption-key-32chars!
- TZ=UTC
volumes:
- n8n_data:/home/node/.n8n
networks:
- delux_network
depends_on:
postgres:
condition: service_healthy
volumes:
n8n_data:
driver: local
postgres_data:
driver: local
networks:
delux_network:
external: trueEnvironment Variables
Key configuration variables:
| Variable | Description | Example |
|---|---|---|
N8N_HOST | Domain name for n8n | n8n.example.com |
N8N_PORT | Port n8n listens on | 5678 |
N8N_PROTOCOL | HTTP or HTTPS | https |
WEBHOOK_URL | External URL for webhooks | https://n8n.example.com |
N8N_BASIC_AUTH_ACTIVE | Enable basic auth | true |
N8N_BASIC_AUTH_USER | Basic auth username | admin |
N8N_BASIC_AUTH_PASSWORD | Basic auth password | Secure password |
N8N_ENCRYPTION_KEY | Key for encrypting credentials | 32-character string |
Nginx Reverse Proxy Configuration
n8n requires WebSocket upgrade support. Configure Nginx:
upstream n8n_backend {
server 127.0.0.1:5678;
}
server {
listen 80;
listen [::]:80;
server_name n8n.example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name n8n.example.com;
ssl_certificate /etc/letsencrypt/live/n8n.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/n8n.example.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
client_max_body_size 50M;
location / {
proxy_pass http://n8n_backend;
proxy_http_version 1.1;
# WebSocket upgrade (critical for n8n)
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;
# Timeouts for long-running workflows
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
}Reload Nginx:
sudo systemctl reload nginxFirst Login and Setup
- Access n8n at
https://n8n.example.com - Log in with credentials from environment variables
- Change the default password immediately
- Create your owner account
- Accept the terms and start building workflows
Example Workflows
Workflow 1: HTTP Webhook to Email
- Create new workflow
- Add trigger: Webhook (Listen on POST)
- Add node: HTTP Request (send data to external API)
- Add node: Email (send notification)
- Test webhook endpoint
- Activate workflow
Workflow 2: Scheduled API Request
- Create new workflow
- Add trigger: Schedule (e.g., every hour)
- Add node: HTTP Request (GET/POST to your API)
- Add node: Set (transform data if needed)
- Add node: Slack (send result to channel)
- Activate workflow
Production Database Configuration
For external PostgreSQL server:
n8n:
environment:
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres.deluxhost.local
- DB_POSTGRESDB_PORT=5432
- DB_POSTGRESDB_DATABASE=n8n
- DB_POSTGRESDB_USER=n8n
- DB_POSTGRESDB_PASSWORD=securepass
- DB_POSTGRESDB_SSL=trueCreate database and user:
CREATE DATABASE n8n;
CREATE USER n8n WITH PASSWORD 'securepass';
GRANT ALL PRIVILEGES ON DATABASE n8n TO n8n;Updating n8n
Pull the latest image and recreate the container:
docker-compose pull
docker-compose up -dn8n automatically migrates the database schema.
n8n stores all credentials encrypted using the N8N_ENCRYPTION_KEY. Back up this key in a secure location. If you lose it, you cannot decrypt existing credentials. Store it in your password manager or encrypted backup system.
Backup and Restore
Backup n8n data:
docker-compose exec n8n tar czf - /home/node/.n8n > n8n_backup.tar.gzBackup PostgreSQL database:
docker-compose exec postgres pg_dump -U n8n n8n | gzip > n8n_db_backup.sql.gzRestore when needed:
docker-compose exec -T postgres psql -U n8n n8n < n8n_db_backup.sql
docker exec n8n tar xzf - /home/node/.n8n < n8n_backup.tar.gz
docker-compose restart n8nMonitoring and Logs
View n8n logs:
docker-compose logs -f n8nMonitor resource usage:
docker stats n8n