Running Multiple n8n Instances on a Self-Hosted Server

Describe the problem/error/question

Introduction: Hello, community members! I’m reaching out to tap into the collective wisdom of our community to seek guidance on a challenge I’m currently facing with my infrastructure setup on a self-hosted server.

The Challenge: In my current self-hosted server environment, I’ve successfully deployed an instance of n8n, a robust workflow automation tool, along with Traefik serving as a reverse proxy to manage incoming traffic. However, I’m encountering difficulties as I attempt to deploy a second instance of n8n.

Key Details:

  • Port Mapping Challenge: n8n only exposes its internal port (5678), making it challenging to map different external ports for multiple instances.
  • Traefik Configuration: Configuring Traefik to efficiently route traffic for multiple n8n instances based on domains or paths has proven to be more complex than anticipated.
  • Server Configuration: Tweaking the server configuration to handle multiple instances while ensuring proper security and resource utilization is an ongoing challenge.

Desired Outcome: My ultimate goal is to have multiple instances of n8n running concurrently on my self-hosted server, each accessible through Traefik, ensuring seamless workflow automation.

Seeking Community Assistance: If anyone in our community has experience with running multiple n8n instances on a self-hosted server or expertise in Traefik configurations, I would greatly appreciate your guidance. Specifically, any insights on how to overcome the port mapping limitations of n8n and optimal Traefik configurations for routing traffic to distinct n8n instances would be immensely helpful.

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 1.25.1
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Linux

Hey @dlteklabs,

I run about 4 instances of n8n in my home setup but I don’t use Traefik I use nginx as my reverse proxy of choice.

What I do is I run n8n in containers and map the host port to something different so 10001 maps to container 1 on port 5678, 10002 maps to container 2 on 5678 and so on. Then in my reverse proxy configuration I direct the traffic to the local IP on the 1000x port. In theory you could also do this with private networks and using machine names but that depends on how good your Docker knowledge is.

For the Traefik configuration I don’t have any examples on that but looking at this it might just be a case of adding labels to your containers.

2 Likes

Wow, great @Jon!
Thank you for your quick response!
Let me try first then if it’s worked I’ll post it here for our community.

1 Like

Here is my doker-compose.yaml file, which create two n8n instances and traefik for reverse proxy.

version: '3.7'

services:
  traefik:
    image: 'traefik'
    restart: always
    command:
      - '--api=true'
      - '--api.insecure=true'
      - '--providers.docker=true'
      - '--providers.docker.exposedbydefault=false'
      - '--entrypoints.web.address=:80'
      - '--entrypoints.web.http.redirections.entryPoint.to=websecure'
      - '--entrypoints.web.http.redirections.entrypoint.scheme=https'
      - '--entrypoints.websecure.address=:443'
      - '--certificatesresolvers.mytlschallenge.acme.tlschallenge=true'
      - '--certificatesresolvers.mytlschallenge.acme.email=${SSL_EMAIL}'
      - '--certificatesresolvers.mytlschallenge.acme.storage=/letsencrypt/acme.json'
    ports:
      - '80:80'
      - '443:443'
      - '8080:8080'
    volumes:
      - traefik_data:/letsencrypt
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - traefik    

  n8n1:
    container_name: n8n1
    image: docker.n8n.io/n8nio/n8n
    restart: always
    ports:
      - '127.0.0.1:5678:5678'
    labels:
      - traefik.enable=true
      - traefik.http.routers.n8n1.rule=Host(`n8n1.${DOMAIN_NAME}`)
      - traefik.http.routers.n8n1.tls=true
      - traefik.http.routers.n8n1.entrypoints=web,websecure
      - traefik.http.routers.n8n1.tls.certresolver=mytlschallenge
      - traefik.http.middlewares.n8n1.headers.SSLRedirect=true
      - traefik.http.middlewares.n8n1.headers.STSSeconds=315360000
      - traefik.http.middlewares.n8n1.headers.browserXSSFilter=true
      - traefik.http.middlewares.n8n1.headers.contentTypeNosniff=true
      - traefik.http.middlewares.n8n1.headers.forceSTSHeader=true
      - traefik.http.middlewares.n8n1.headers.SSLHost=n8n1
      - traefik.http.middlewares.n8n1.headers.STSIncludeSubdomains=true
      - traefik.http.middlewares.n8n1.headers.STSPreload=true
      - traefik.http.routers.n8n1.middlewares=n8n1@docker
    environment:
      - N8N_HOST=n8n1.${DOMAIN_NAME}
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
      - N8N_VERSION_NOTIFICATIONS_ENABLED=true
      - NODE_ENV=production
      - N8N_METRICS=true
      - QUEUE_HEALTH_CHECK_ACTIVE=true
      - WEBHOOK_URL=n8n1.${DOMAIN_NAME}/
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
    volumes:
      - n8n1_data:/home/node/.n8n
    networks:
      - traefik

  n8n2:
    container_name: n8n2
    image: docker.n8n.io/n8nio/n8n
    restart: always
    ports:
      - '127.0.0.1:8081:5678'
    labels:
      - traefik.enable=true
      - traefik.http.routers.n8n2.rule=Host(`n8n2.${DOMAIN_NAME}`)
      - traefik.http.routers.n8n2.tls=true
      - traefik.http.routers.n8n2.entrypoints=web,websecure
      - traefik.http.routers.n8n2.tls.certresolver=mytlschallenge
      - traefik.http.middlewares.n8n2.headers.SSLRedirect=true
      - traefik.http.middlewares.n8n2.headers.STSSeconds=315360000
      - traefik.http.middlewares.n8n2.headers.browserXSSFilter=true
      - traefik.http.middlewares.n8n2.headers.contentTypeNosniff=true
      - traefik.http.middlewares.n8n2.headers.forceSTSHeader=true
      - traefik.http.middlewares.n8n2.headers.SSLHost=n8n2
      - traefik.http.middlewares.n8n2.headers.STSIncludeSubdomains=true
      - traefik.http.middlewares.n8n2.headers.STSPreload=true
      - traefik.http.routers.n8n2.middlewares=n8n2@docker
    environment:
      - N8N_HOST=n8n2.${DOMAIN_NAME}
      - N8N_PORT=8081
      - N8N_PROTOCOL=https
      - N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
      - N8N_VERSION_NOTIFICATIONS_ENABLED=true
      - NODE_ENV=production
      - N8N_METRICS=true
      - QUEUE_HEALTH_CHECK_ACTIVE=true
      - WEBHOOK_URL=n8n2.${DOMAIN_NAME}/
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
    volumes:
      - n8n2_data:/home/node/.n8n
    networks:
      - traefik

volumes:
  n8n1_data:
    external: true
  n8n2_data:
    external: true
  traefik_data:
    external: true

networks:
  traefik:
    external: true

If someone has ideas for improvement, don’t hesitate, you are welcome!

1 Like

I’ve published a post on how to setup multiple n8n instances with docker and traefik in case someone needs a detailed guide.

2 Likes

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