SESSION LIVE--:-- // YOU: SCANNING
    BACK_TO_INTEL
    Automation

    Self-Hosting n8n Like a DevOps Deity: Docker, PostgreSQL, Nginx & Let’s Encrypt on Ubuntu

    Tired of subscription fees and cloud lock-in? This no-fluff, brutally honest guide walks you through deploying a production-ready n8n automation server on your own Ubuntu droplet — with Docker, PostgreSQL, Nginx, HTTPS, and enough sarcasm to keep things human. Get ready to automate everything… your way.

    Satvik Vemulapalli10 Min130 views1 likes
    Self-Hosting n8n Like a DevOps Deity: Docker, PostgreSQL, Nginx & Let’s Encrypt on Ubuntu
    IMAGE SIZE

    🛠️ How to Self-Host n8n Like a Pro on Ubuntu (With Docker, PostgreSQL, Nginx & HTTPS)

    "Why pay for automation when you can build it, break it, and fix it yourself?"

    Welcome to the definitive guide for deploying a production-grade instance of n8n — the popular open-source workflow automation tool — on a DigitalOcean Droplet running Ubuntu 20.04/22.04. This guide uses Docker, PostgreSQL, Nginx, and Let’s Encrypt to give you a solid, secure, and scalable setup.

    You’re not here for fluff, so let’s dive in.


    🧰 Tech Stack

    • OS: Ubuntu 20.04 or 22.04
    • Automation Engine: n8n (Dockerized)
    • Database: PostgreSQL (because SQLite is cute, but not production-ready)
    • Web Server: Nginx (to keep the bad bots out)
    • SSL: Let’s Encrypt (because HTTP is for amateurs)
    • Domain: Optional, but do yourself a favor and use one

    ⚙️ Step 1: SSH and Basic Housekeeping

    SSH into your Droplet (replace the IP with yours):

    ssh root@192.241.146.80
    

    Update the OS and install essentials:

    apt update && apt upgrade -y
    apt install -y curl ufw nano
    

    🐳 Step 2: Install Docker & Docker Compose

    Install Docker:

    apt install -y docker.io
    systemctl enable docker --now
    

    Install Docker Compose (no snap BS here):

    curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    chmod +x /usr/local/bin/docker-compose
    

    Verify installation like a responsible admin:

    docker --version
    docker-compose --version
    

    📁 Step 3: Create the Project Directory

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

    🐋 Step 4: The Docker Compose You’ll Marry

    Create your Docker Compose file:

    nano docker-compose.yml
    

    Paste this masterpiece:

    version: '3.8'
    
    services:
      postgres:
        image: postgres:15
        restart: always
        environment:
          POSTGRES_USER: n8n
          POSTGRES_PASSWORD: n8npassword
          POSTGRES_DB: n8n
        volumes:
          - pgdata:/var/lib/postgresql/data
    
      n8n:
        image: n8nio/n8n
        restart: always
        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=n8npassword
          - N8N_BASIC_AUTH_ACTIVE=true
          - N8N_BASIC_AUTH_USER=admin
          - N8N_BASIC_AUTH_PASSWORD=SatvikPassword123@
          - N8N_HOST=192.241.146.80
          - N8N_PORT=5678
          - N8N_PROTOCOL=https
          - N8N_SECURE_COOKIE=true
          - NODE_ENV=production
        volumes:
          - n8n_data:/home/node/.n8n
        depends_on:
          - postgres
    
    volumes:
      n8n_data:
      pgdata:
    

    🚀 Step 5: Launch Your Stack

    docker-compose up -d
    docker ps
    

    Test access (expect a security warning if SSL isn’t ready):

    http://192.241.146.80:5678


    🌐 Step 6: (Optional) Point a Domain Like a Grown-Up

    At your DNS provider, add this A record:

    • Type: A
    • Host: n8n
    • Value: 192.241.146.80
    • TTL: Automatic or 3600

    So you can access your setup at something like: n8n.yourdomain.com


    🌎 Step 7: Install Nginx & Certbot for HTTPS

    Install Nginx and Let’s Encrypt:

    apt install -y nginx certbot python3-certbot-nginx
    ufw allow 'Nginx Full'
    ufw enable
    

    🧱 Step 8: Nginx Config Time

    Create your Nginx config:

    nano /etc/nginx/sites-available/n8n
    

    Paste the following (replace the domain):

    server {
        listen 80;
        server_name n8n.example.com;
    
        location / {
            proxy_pass http://localhost:5678;
            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;
        }
    }
    

    Enable the config:

    ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/
    nginx -t && systemctl reload nginx
    

    🔐 Step 9: SSL with Let’s Encrypt

    Run:

    certbot --nginx -d n8n.example.com
    

    Choose Redirect when prompted (because again, HTTP is for peasants).


    ♻️ Restart Docker Stack with HTTPS

    After SSL is live, update your environment (if needed) and restart Docker:

    cd /opt/n8n
    docker-compose down
    docker-compose up -d
    

    ✅ Step 10: Verify It All Works

    Check these:

    • Access via https://n8n.example.com
    • Prompts for basic auth login
    • PostgreSQL is connected (check with docker logs)
    • SSL is working with that juicy padlock

    Login credentials:

    • Username: admin@domain.com
    • Password: SatvikPassword123@

    🎁 Bonus Round: Optional Upgrades

    Want to level up your setup? Consider:

    • 💾 Backups: Use volume mounts + cron or restic
    • 📧 SMTP Email Alerts: For failed workflows or errors
    • 📈 Monitoring: Setup Portainer, Watchtower, or Prometheus/Grafana
    • 🔒 Security: Install fail2ban, use UFW rules, disable root SSH

    🏁 You're Done

    Congrats! You now have a secure, scalable, self-hosted n8n instance humming on your own Ubuntu Droplet like the control freak you were born to be.

    Welcome to the world of infinite automation without the SaaS tax.

    Enjoyed this report?

    If it helped, like it and pass it on to someone who needs it.

    BROADCAST
    RELATED_REPORTS
    Loading comments...