n8n Workflow Automation Instaleation

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.

Tabla de contenidos

Requisitos previos

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

Requisitos del sistema

Verifique las especificaciones del sistema:

Check OS version:

cat /etc/os-release
uname -m

Check available resources:

free -h
df -h

Docker Instaleation

Instale Docker and Docker Compose:

sudo apt install -y docker.io docker-compose

Add user to docker group:

sudo usermod -aG docker $USER
newgrp docker

Verifique installation:

docker --version
docker-compose --version

Start Docker:

sudo systemctl start docker
sudo systemctl enable docker

PostgreSQL Setup

Cree PostgreSQL data directory:

sudo mkdir -p /var/lib/postgresql-n8n
sudo chown -R $USER:$USER /var/lib/postgresql-n8n

Cree 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

Verifique PostgreSQL is running:

docker ps | grep postgres

n8n Implementement

Cree n8n directory:

mkdir -p /opt/n8n
cd /opt/n8n

Cree 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

Cree data directory:

mkdir -p /opt/n8n/data

Start n8n containers:

docker-compose up -d

Verifique containers are running:

docker-compose ps
docker-compose logs -f n8n

Wait for initialization to complete.

Configuración de Nginx

Instale Nginx:

sudo apt install -y nginx

Cree 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

Configuración del certificado SSL

Instale Certbot:

sudo apt install -y certbot python3-certbot-nginx

Obtain SSL certificate:

sudo certbot certonly --standalone -d workflow.example.com

Verifique certificate:

sudo openssl x509 -in /etc/letsencrypt/live/workflow.example.com/fullchain.pem -noout -dates

Configure auto-renewal:

sudo systemctl enable certbot.timer
sudo systemctl start certbot.timer

Configuración inicial

Access n8n interface:

Navigate to https://workflow.example.com

Complete initial setup:

  1. Cree admin account
  2. Configure email (optional)
  3. Accept user agreement

Configure instance settings:

  1. Settings (gear icon)
    • Set timezone
    • Configure execution mode
    • Set resource limits

Enable webhooks:

  1. Settings → Webhook
  2. Configure webhook URL
  3. Enable for external integrations

Workflow Creation

Cree new workflow:

  1. Click "New Workflow"
  2. Give workflow a name
  3. Start building

Add nodes to workflow:

  1. Click "+" to add node
  2. Search for service (Slack, Gmail, etc.)
  3. Configure node settings

Connect nodes:

  1. Drag connection from node output
  2. Connect to next node input
  3. 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:

  1. Click "Test" button
  2. Execute sample data
  3. View results in execution history

Implemente workflow:

  1. Click "Activate" toggle
  2. Workflow runs in production
  3. Monitor execution logs

Credential Management

Add credentials:

  1. Click "Credentials" (top left)
  2. Click "New Credential"
  3. Select service type
  4. Enter credentials/API keys

Manage credentials:

  1. View all stored credentials
  2. Edit credentials as needed
  3. Test credential connection
  4. Delete unused credentials

Add webhook credential:

  1. New Credential → Webhook
  2. Set username/password
  3. Use in webhook auth

Add API credential:

  1. New Credential → API Generic
  2. Enter API endpoint
  3. Configure headers
  4. Set authentication type

Backup Strategy

Cree 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

Conclusión

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. Cree 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.