How to Setup n8n to Own Domain

Setting up n8n on your own domain might sound complex, but it's actually quite straightforward once you break it down into simple steps. Having n8n running on your own domain gives you complete control over your automation workflows, ensures your data stays private, and allows you to access your workflows from anywhere with a professional URL.

Hii I am Bishworaj Poudel and in this guide, I'll walk you through setting up n8n on your own domain using DigitalOcean, Docker, and Caddy (for automatic HTTPS). By the end, you'll have n8n running securely on your domain with automatic SSL certificates.


Why Self-Host n8n on Your Own Domain?

There are multiple hosting options available, but I've been using DigitalOcean since 2017 and highly recommend it for its reliability, simplicity, and excellent documentation. Self-hosting n8n on your own domain gives you:

  • Complete data privacy - Your workflows and data stay on your server
  • Professional URL - Access n8n via n8n.yourdomain.com instead of a random IP
  • Automatic HTTPS - Caddy handles SSL certificates automatically
  • Full control - You decide when to update, backup, and configure
  • Cost-effective - No per-task fees like cloud automation services

Prerequisites

Before we begin, make sure you have:

  1. A DigitalOcean account (you can get $200 free credit for 2 months!)
  2. A domain name (you can buy one from Namecheap, GoDaddy, or any registrar)
  3. Basic familiarity with terminal/SSH (we'll guide you through everything)

Step 1: Create a Droplet on DigitalOcean

Get Started with $200 Free Credit

Use this referral link to get $200 free credit for 2 months on DigitalOcean:

Get $200 Free For 2 Month On DigitalOcean

This is perfect for learning and experimenting with your first server!

Create Your Droplet

  1. Log in to your DigitalOcean dashboard
  2. Click CreateDroplets
  3. Choose Region: Select the closest region to your users
  4. Choose OS: Select Ubuntu (22.04 or 24.04 LTS recommended)
  5. Choose Plan: Start with the Basic plan ($6/month is perfect for n8n)
  6. Add SSH Keys: Select your SSH key (or create one if you haven't)
  7. Finalize: Give your droplet a name (e.g., "n8n-server")
  8. Click Create Droplet

Wait 1-2 minutes for your droplet to be created. You'll see your server's IP address once it's ready.


Step 2: SSH into Your Server and Install Docker

Connect to Your Server

Once your droplet is created, connect to it using SSH:

1ssh root@<Your IP Address>

Example:

Update System and Install Docker

Once connected, run these commands to update your system and install Docker:

1apt update && apt -y upgrade
2apt install -y ca-certificates curl gnupg ufw openssl
3ufw allow OpenSSH
4ufw --force enable

Install Docker repository:

1install -m 0755 -d /etc/apt/keyrings
2curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
3chmod a+r /etc/apt/keyrings/docker.gpg

Add Docker to package sources:

1. /etc/os-release
2echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu ${VERSION_CODENAME} stable" \
3  > /etc/apt/sources.list.d/docker.list

Install Docker:

1apt update
2apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
3systemctl enable --now docker
4docker compose version

You should see the Docker Compose version displayed, confirming Docker is installed correctly.


Step 3: Set Up Domain and Create n8n Configuration

Configure Domain Variables

Replace yourdomain.com with your actual domain name. Run these commands:

1export DOMAIN_NAME="yourdomain.com"
2export SUBDOMAIN="n8n"
3export FULL_DOMAIN="${SUBDOMAIN}.${DOMAIN_NAME}"
4export TZ="Asia/Kathmandu"

Example:

1export DOMAIN_NAME="example.com"
2export SUBDOMAIN="n8n"
3export FULL_DOMAIN="n8n.example.com"
4export TZ="Asia/Kathmandu"

Create n8n Directory

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

Generate Secure Passwords

Generate secure random passwords for PostgreSQL and n8n authentication:

1export POSTGRES_PASSWORD="$(openssl rand -base64 24 | tr -d '\n')"
2export N8N_ENCRYPTION_KEY="$(openssl rand -hex 32)"
3export N8N_BASIC_AUTH_USER="admin"
4export N8N_BASIC_AUTH_PASSWORD="$(openssl rand -base64 24 | tr -d '\n')"

Create Environment File

Create the .env file with all configuration:

 1cat > /opt/n8n/.env <<EOF
 2DOMAIN_NAME=${DOMAIN_NAME}
 3SUBDOMAIN=${SUBDOMAIN}
 4GENERIC_TIMEZONE=${TZ}
 5
 6POSTGRES_DB=n8n
 7POSTGRES_USER=n8n
 8POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
 9
10N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
11
12N8N_BASIC_AUTH_ACTIVE=true
13N8N_BASIC_AUTH_USER=${N8N_BASIC_AUTH_USER}
14N8N_BASIC_AUTH_PASSWORD=${N8N_BASIC_AUTH_PASSWORD}
15EOF

Secure the environment file:

1chmod 600 /opt/n8n/.env

Important: Save your passwords! You can view them later with:

1cat /opt/n8n/.env

Step 4: Create Caddy Configuration and Docker Compose

Create Caddyfile (HTTPS Configuration)

Caddy will automatically handle SSL certificates for your domain:

1cat > /opt/n8n/Caddyfile <<EOF
2${FULL_DOMAIN} {
3  encode gzip
4  reverse_proxy n8n:5678
5}
6EOF

Create Docker Compose File

Create the docker-compose.yml file that defines all services:

 1cat > /opt/n8n/docker-compose.yml <<'EOF'
 2services:
 3  postgres:
 4    image: postgres:16-alpine
 5    restart: unless-stopped
 6    environment:
 7      POSTGRES_USER: ${POSTGRES_USER}
 8      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
 9      POSTGRES_DB: ${POSTGRES_DB}
10    volumes:
11      - postgres_data:/var/lib/postgresql/data
12    healthcheck:
13      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
14      interval: 10s
15      timeout: 5s
16      retries: 10
17
18  n8n:
19    image: n8nio/n8n:stable
20    restart: unless-stopped
21    depends_on:
22      postgres:
23        condition: service_healthy
24    environment:
25      - DB_TYPE=postgresdb
26      - DB_POSTGRESDB_HOST=postgres
27      - DB_POSTGRESDB_PORT=5432
28      - DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
29      - DB_POSTGRESDB_USER=${POSTGRES_USER}
30      - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
31
32      - N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
33      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
34      - TZ=${GENERIC_TIMEZONE}
35
36      - N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME}
37      - N8N_PORT=5678
38      - N8N_PROTOCOL=https
39      - WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
40      - N8N_PROXY_HOPS=1
41      - N8N_EDITOR_BASE_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
42
43      - N8N_BASIC_AUTH_ACTIVE=${N8N_BASIC_AUTH_ACTIVE}
44      - N8N_BASIC_AUTH_USER=${N8N_BASIC_AUTH_USER}
45      - N8N_BASIC_AUTH_PASSWORD=${N8N_BASIC_AUTH_PASSWORD}
46
47      - NODE_ENV=production
48      - N8N_RUNNERS_ENABLED=true
49    volumes:
50      - n8n_data:/home/node/.n8n
51
52  caddy:
53    image: caddy:2-alpine
54    restart: unless-stopped
55    ports:
56      - "80:80"
57      - "443:443"
58    volumes:
59      - ./Caddyfile:/etc/caddy/Caddyfile:ro
60      - caddy_data:/data
61      - caddy_config:/config
62    depends_on:
63      - n8n
64
65volumes:
66  n8n_data:
67  postgres_data:
68  caddy_data:
69  caddy_config:
70EOF

Step 5: Configure DNS and Open Firewall Ports

Configure DNS Records

Before starting n8n, you need to point your domain to your server:

  1. Go to your domain registrar (Namecheap, GoDaddy, etc.)
  2. Navigate to DNS settings
  3. Add an A record:
    • Type: A
    • Host: n8n (or your subdomain)
    • Value: Your server's IP address (from DigitalOcean)
    • TTL: 3600 (or default)

Example:

  • Host: n8n
  • Points to: 68.183.85.9
  • This creates: n8n.yourdomain.com

Note: DNS changes can take a few minutes to several hours to propagate. You can check if it's ready using:

1ping n8n.yourdomain.com

Open Firewall Ports

Allow HTTP and HTTPS traffic:

1ufw allow 80/tcp
2ufw allow 443/tcp

Step 6: Start n8n

Launch n8n Services

Navigate to the n8n directory and start all services:

1cd /opt/n8n
2docker compose up -d

The -d flag runs containers in the background (detached mode).

Check Service Status

Verify all services are running:

1docker compose ps

You should see all three services (postgres, n8n, caddy) with status "Up".

View Logs (Optional)

If you want to see what's happening, check the logs:

1docker compose logs -f

Press Ctrl+C to exit the logs view.


Step 7: Access Your n8n Instance

Wait for DNS Propagation

After starting the services, wait a few minutes for:

  1. DNS to propagate (if you just added the DNS record)
  2. Caddy to obtain SSL certificate (automatic)
  3. n8n to initialize

Access n8n

Open your browser and go to:

1https://n8n.yourdomain.com

Note: Replace n8n.yourdomain.com with your actual subdomain.

Login

You'll be prompted for basic authentication:

  • Username: admin (or the username you set in N8N_BASIC_AUTH_USER)
  • Password: The password generated in Step 3 (check /opt/n8n/.env)

After logging in, you'll see the n8n interface and can start creating workflows!


Step 8: Update n8n (When Needed)

To update n8n to the latest version in the future:

1cd /opt/n8n
2docker compose pull
3docker compose up -d

This downloads the latest images and restarts the services with zero downtime.


💡 Pro Tips

  • Backup your .env file: Keep a secure copy of /opt/n8n/.env with your passwords
  • Regular updates: Update n8n monthly to get security patches and new features
  • Monitor disk space: n8n data grows over time, monitor your server's disk usage
  • Backup workflows: Export important workflows from n8n interface as JSON files
  • Use strong passwords: The generated passwords are secure, but you can change them in .env if needed
  • Check logs if issues occur: Use docker compose logs to troubleshoot problems


Learn More About Automation and Server Management

Join our community of developers: