If you want to install n8n on Ubuntu 24.04 in a secure and production-ready way, this guide walks through a complete setup using Docker, CloudPanel, and Cloudflare.

This approach avoids exposing ports, supports HTTPS properly, and ensures n8n restarts automatically after a server reboot.


What You Will Build

  • Self-hosted n8n on Ubuntu 24.04
  • Docker-based installation
  • CloudPanel reverse proxy
  • Cloudflare DNS and SSL
  • Automatic restart on reboot

Final Architecture Overview

Browser
 → Cloudflare (DNS + SSL)
 → CloudPanel (Nginx Reverse Proxy)
 → Docker Container (n8n on localhost)

n8n runs only on localhost and is never exposed directly to the internet.


Step 1: Install Docker on Ubuntu 24.04

sudo apt update && sudo apt upgrade -y
curl -fsSL https://get.docker.com | sudo sh
sudo systemctl enable docker
sudo systemctl start docker

Verify installation:

docker --version
docker compose version

Step 2: Configure Cloudflare DNS and SSL

Add an A record in Cloudflare DNS:

Type Name Value
A n8n Your VPS IP

Enable the orange cloud (proxy).

In SSL/TLS settings:

  • SSL Mode: Full (strict)
  • Always Use HTTPS: ON

Step 3: Create n8n Directory

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

Step 4: Create Docker Compose Configuration

Type in bash “nano /opt/n8n/docker-compose.yml”

Now edit this below line with your username, password and the domain you want to use for then paste it.

version: "3.8"

services:
  n8n:
    image: n8nio/n8n:latest
    container_name: n8n
    restart: unless-stopped

    ports:
      - "127.0.0.1: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=your_username
      - N8N_BASIC_AUTH_PASSWORD=your_strong_password

      - TZ=UTC

    volumes:
      - n8n_data:/home/node/.n8n

volumes:
  n8n_data:

Step 5: Start n8n

docker compose up -d
docker ps
docker logs n8n --tail=20

You should see Editor is now accessible.


Step 6: Configure Reverse Proxy in CloudPanel

  • Site Type: Reverse Proxy
  • Domain: n8n.example.com
  • Forward Host: 127.0.0.1
  • Forward Port: 5678

Step 7: Enable HTTPS (Let’s Encrypt)

Enable Let’s Encrypt and force HTTPS inside CloudPanel. Wait 1–2 minutes for certificate issuance.


Automatic Restart After Reboot

The following Docker setting ensures n8n restarts automatically:

restart: unless-stopped

No systemd or cron jobs are required.


Common Issues and Fixes

Browser shows “Dangerous Site”

  • Cloudflare SSL must be Full (strict)
  • Let’s Encrypt must be enabled in CloudPanel

Webhooks not working

  • WEBHOOK_URL must match the domain exactly
  • HTTPS must be enabled

n8n container not running

docker logs n8n

Conclusion

This is a secure and production-ready method to self-host n8n on Ubuntu 24.04 using Docker, CloudPanel, and Cloudflare.

The setup supports HTTPS, automatic restarts, and clean reverse proxy handling—making it suitable for real-world automation workloads.

Tags: