n8n Workflow Automation Installation
n8n is an open-source workflow automation platform enabling complex automations without coding. With a visual interface and hundreds of pre-built integrations, n8n connects services like Slack, Gmail, Google Sheets, and custom APIs. This guide covers Docker deployment, PostgreSQL setup, Nginx configuration, credential management, and workflow automation.
Table of Contents
- Prerequisites
- System Requirements
- Docker Installation
- PostgreSQL Setup
- n8n Deployment
- Nginx Configuration
- SSL Certificate Setup
- Initial Configuration
- Workflow Creation
- Credential Management
- Backup Strategy
- Conclusion
Prerequisites
Ensure you have:
- Ubuntu 20.04 LTS or later
- Root or sudo access
- A registered domain name
- Minimum 2GB RAM (4GB+ recommended)
- 20GB available disk space
- Basic Linux administration knowledge
Update system:
sudo apt update && sudo apt upgrade -y
System Requirements
Verify system specifications:
Check OS version:
cat /etc/os-release
uname -m
Check available resources:
free -h
df -h
Docker Installation
Install Docker and Docker Compose:
sudo apt install -y docker.io docker-compose
Add user to docker group:
sudo usermod -aG docker $USER
newgrp docker
Verify installation:
docker --version
docker-compose --version
Start Docker:
sudo systemctl start docker
sudo systemctl enable docker
PostgreSQL Setup
Create PostgreSQL data directory:
sudo mkdir -p /var/lib/postgresql-n8n
sudo chown -R $USER:$USER /var/lib/postgresql-n8n
Create PostgreSQL container:
docker run -d \
--name postgres-n8n \
-e POSTGRES_DB=n8n \
-e POSTGRES_USER=n8n \
-e POSTGRES_PASSWORD=SecurePassword123! \
-v /var/lib/postgresql-n8n:/var/lib/postgresql/data \
postgres:13-alpine
Verify PostgreSQL is running:
docker ps | grep postgres
n8n Deployment
Create n8n directory:
mkdir -p /opt/n8n
cd /opt/n8n
Create docker-compose.yml:
nano docker-compose.yml
Add configuration:
version: '3'
services:
n8n:
image: n8nio/n8n:latest
restart: always
ports:
- "5678:5678"
environment:
DB_TYPE: postgres
DB_POSTGRESDB_HOST: postgres-n8n
DB_POSTGRESDB_PORT: 5432
DB_POSTGRESDB_DATABASE: n8n
DB_POSTGRESDB_USER: n8n
DB_POSTGRESDB_PASSWORD: SecurePassword123!
N8N_HOST: workflow.example.com
N8N_PORT: 5678
N8N_PROTOCOL: https
NODE_ENV: production
WEBHOOK_TUNNEL_URL: https://workflow.example.com/
GENERIC_TIMEZONE: UTC
volumes:
- /opt/n8n/data:/home/node/.n8n
depends_on:
- postgres-n8n
networks:
- n8n
postgres-n8n:
image: postgres:13-alpine
restart: always
environment:
POSTGRES_DB: n8n
POSTGRES_USER: n8n
POSTGRES_PASSWORD: SecurePassword123!
volumes:
- /var/lib/postgresql-n8n:/var/lib/postgresql/data
networks:
- n8n
networks:
n8n:
driver: bridge
Create data directory:
mkdir -p /opt/n8n/data
Start n8n containers:
docker-compose up -d
Verify containers are running:
docker-compose ps
docker-compose logs -f n8n
Wait for initialization to complete.
Nginx Configuration
Install Nginx:
sudo apt install -y nginx
Create Nginx configuration:
sudo nano /etc/nginx/sites-available/n8n
Add configuration:
upstream n8n {
server localhost:5678;
}
server {
listen 80;
listen [::]:80;
server_name workflow.example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name workflow.example.com;
ssl_certificate /etc/letsencrypt/live/workflow.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/workflow.example.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
client_max_body_size 100M;
location / {
proxy_pass http://n8n;
proxy_http_version 1.1;
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;
proxy_buffering off;
}
}
Enable site:
sudo ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl start nginx
sudo systemctl enable nginx
SSL Certificate Setup
Install Certbot:
sudo apt install -y certbot python3-certbot-nginx
Obtain SSL certificate:
sudo certbot certonly --standalone -d workflow.example.com
Verify certificate:
sudo openssl x509 -in /etc/letsencrypt/live/workflow.example.com/fullchain.pem -noout -dates
Set up auto-renewal:
sudo systemctl enable certbot.timer
sudo systemctl start certbot.timer
Initial Configuration
Access n8n interface:
Navigate to https://workflow.example.com
Complete initial setup:
- Create admin account
- Configure email (optional)
- Accept user agreement
Configure instance settings:
- Settings (gear icon)
- Set timezone
- Configure execution mode
- Set resource limits
Enable webhooks:
- Settings → Webhook
- Configure webhook URL
- Enable for external integrations
Workflow Creation
Create new workflow:
- Click "New Workflow"
- Give workflow a name
- Start building
Add nodes to workflow:
- Click "+" to add node
- Search for service (Slack, Gmail, etc.)
- Configure node settings
Connect nodes:
- Drag connection from node output
- Connect to next node input
- Map data between nodes
Example: Send Slack message on webhook:
1. Add "Webhook" node
2. Add "Slack" node (send message)
3. Map webhook data to Slack fields
4. Save and activate workflow
5. Get webhook URL
6. Test with POST request
Test workflow:
- Click "Test" button
- Execute sample data
- View results in execution history
Deploy workflow:
- Click "Activate" toggle
- Workflow runs in production
- Monitor execution logs
Credential Management
Add credentials:
- Click "Credentials" (top left)
- Click "New Credential"
- Select service type
- Enter credentials/API keys
Manage credentials:
- View all stored credentials
- Edit credentials as needed
- Test credential connection
- Delete unused credentials
Add webhook credential:
- New Credential → Webhook
- Set username/password
- Use in webhook auth
Add API credential:
- New Credential → API Generic
- Enter API endpoint
- Configure headers
- Set authentication type
Backup Strategy
Create backup script:
sudo nano /usr/local/bin/n8n-backup.sh
Add:
#!/bin/bash
BACKUP_DIR="/backups/n8n"
N8N_DIR="/opt/n8n"
DATE=$(date +%Y%m%d_%H%M%S)
mkdir -p $BACKUP_DIR
# Database backup
docker exec postgres-n8n pg_dump -U n8n n8n | gzip > "$BACKUP_DIR/n8n-db-$DATE.sql.gz"
# Data backup
tar -czf "$BACKUP_DIR/n8n-data-$DATE.tar.gz" "$N8N_DIR/data"
# Keep only 30 days
find $BACKUP_DIR -type f -mtime +30 -delete
echo "Backup completed: $DATE"
Make executable:
sudo chmod +x /usr/local/bin/n8n-backup.sh
Schedule daily backups:
sudo crontab -e
Add:
0 2 * * * /usr/local/bin/n8n-backup.sh >> /var/log/n8n-backup.log 2>&1
Update n8n:
cd /opt/n8n
docker-compose pull
docker-compose down
docker-compose up -d
Monitor logs:
docker-compose logs -f n8n
Conclusion
n8n is now fully deployed as a workflow automation platform. With PostgreSQL database, Nginx reverse proxy, SSL encryption, and extensive integration options, you have a powerful automation tool. Create workflows to automate business processes, integrate services, and reduce manual tasks. Store credentials securely and monitor execution history. Regular backups ensure workflow recovery and business continuity.


