How to host n8n with 2 different domains

Hi,

I would like to know how to enable multiple domians on n8n. The reason why I need this is because in some locations, my main domain is block due to it being a “.dev” ending domain which is considered a new and unverified domains.

thus I wanna use it on another domain that is more accessible.

I am using a normal VPS with the docker compose method of hosting. I have the .env setup with my current domain.

The issue I am having when attempting to access the server with the other domain is that the SSL certificate is not valid. (to be expected)

I know this is a weird request but wondering if anyone knows a work around for it.

Hi Bredda,

I have 2 domains (for example, your_firts_domain.com, your_second_domain.com) for same n8n.
both domain share exact same n8n, and I have no issue so far.
You need to get ssl certificate for each domain.

The following is the config files I set. I am using nginx.

This is only docker-compose.yml I’m using for n8n

docker-compose.yml

services:
  n8n:
    image: n8nio/n8n:1.85.4
    container_name: n8n
    restart: always
    environment:
      - N8N_HOST=0.0.0.0  
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - NODE_ENV=production
      - N8N_RUNNERS_ENABLED=true

      - WEBHOOK_URL=https://n8n.your_first_domain.com
      - GENERIC_TIMEZONE=Pacific/Auckland

      - EXPRESS_TRUST_PROXY=true
      - VUE_APP_URL_BASE_API= https://n8n.your_first_domain.com

    volumes:
      - n8n_data:/home/node/.n8n
      - /local-files:/files
    ports:
      - "5678:5678"
    networks:
      - app-network

networks:
  app-network:
    external: true

volumes:
  n8n_data:

=======================
Your first domain conf file
n8n.your_first_domain.com.conf

server {
    listen 80;
    server_name n8n.first_domain.com;

    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name n8n.your_first_domain.com;

    ssl_certificate /etc/letsencrypt/live/your_first_domain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/your_first_domain.com/privkey.pem;

    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;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

===========================
Your second domain conf file
n8n.your_second_domain.com.conf

server {
    listen 80;
    server_name n8n.your_second_domain.com;

    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name n8n.attach2gdrive.com;

    ssl_certificate /etc/letsencrypt/live/your_second_domain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/your_second_domain.com/privkey.pem;

    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;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

=========================

ah I see, you running a reverse proxy with nginx. I was thinking about that but couldnt get the config to work. thanks for sharing that. I will test this tomorrow!

I will let you know my results.

1 Like

Hi, I am back and I am trying to get this to work but I am getting certbot errors when trying to get it to work. could you please expand more on how you set this entirely up with nginx as well?

much appreciated

No one has replied to this yet with a solution…

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.