How to Install n8n Using Docker Compose and Caddy (with HTTPS)


1. Start With a Clean Server


2. Update Your System (Recommended)

apt update && apt upgrade -y

3. Create a Folder for n8n

mkdir -p /root/n8n
cd /root/n8n

4. Create Your docker-compose.yml File

Create and edit the file:

nano /root/n8n/docker-compose.yml

Paste the following content (replace your.domain.com with your actual subdomain):

services:
  n8n:
    image: n8nio/n8n
    container_name: n8n
    restart: unless-stopped
    environment:
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER=admin          # Change this!
      - N8N_BASIC_AUTH_PASSWORD=strongpass # Change this!
      - N8N_HOST=your.domain.com
      - N8N_PORT=5678
      - WEBHOOK_URL=https://your.domain.com/
      - N8N_PROTOCOL=https
      - N8N_SECURE_COOKIE=true
    volumes:
      - ./data:/home/node/.n8n
    networks:
      - n8n_network

  caddy:
    image: caddy:alpine
    container_name: caddy
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - caddy_data:/data
      - caddy_config:/config
    networks:
      - n8n_network

networks:
  n8n_network:

volumes:
  caddy_data:
  caddy_config:

5. Create Your Caddyfile

nano /root/n8n/Caddyfile

Paste this (replace your.domain.com):

your.domain.com {
    reverse_proxy n8n:5678
}

6. Set Permissions (for volume folder)

mkdir -p /root/n8n/data
chown -R 1000:1000 /root/n8n/data

7. Point Your Domain DNS to the Server IP

  • In your domain registrar, create an A record for your.domain.com → your server’s public IP.

8. Start Everything Up

From /root/n8n:

docker compose up -d

9. Open Firewall (if using UFW)

sudo ufw allow 80
sudo ufw allow 443
sudo ufw reload

10. Access n8n!

  • Visit https://your.domain.com in your browser.
  • Log in with the username and password you set in the Compose file.

11. Updating n8n in the Future

docker compose pull
docker compose up -d

12. Restarting After Changes (e.g., new domain in Caddyfile)

docker compose restart caddy

(or docker compose restart to restart all)


Summary Table

StepCommand / FilePurpose
Create dirmkdir -p /root/n8nApp folder
Compose filenano /root/n8n/docker-compose.ymlStack config
Caddyfilenano /root/n8n/CaddyfileHTTPS reverse proxy
Start stackdocker compose up -dRun in background
Firewallufw allow 80; ufw allow 443Allow web access
Update DNSDomain → your server IPDomain resolves

Pro Tips

  • You can change credentials and domain anytime—just update the files and restart.
  • Data is stored in /root/n8n/data—back this up regularly!
  • Caddy will auto-renew your free SSL certificate.
  • No manual SSL setup needed!

Leave a Reply

Your email address will not be published. Required fields are marked *