N8n Multi-Instance Deployment Guide

Multi-Instance n8n Deployment Guide on Ubuntu

A step-by-step procedure for secure installation and independent management of multiple n8n instances on a single host.

1️⃣ User Account Creation

Establish a dedicated, non-root system user (user) for running the n8n processes for enhanced security. This is mandatory for service isolation.

sudo adduser user
sudo usermod -aG sudo user # Optional: Grants user sudo privileges

Switch to the new user before proceeding with the installation:

su user

2️⃣ Node.js (LTS) Installation

Install Node.js (Long-Term Support version recommended) and required build tools.

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash
sudo apt install -y nodejs build-essential
node -v
npm -v

3️⃣ Global n8n Installation

Install the n8n application globally using npm. Verify the executable path for systemd configuration.

sudo npm install -g n8n
which n8n

Expected executable path: /usr/local/bin/n8n

4️⃣ Instance Data Directory Configuration

Create separate data directories for each n8n instance to ensure isolation of databases, credentials, and settings.

Configuration Matrix

Instance NameData FolderInternal PortPublic Domain
n8n/home/user/.n8n5678n8n.example.com
n8n1/home/user/.n8n15680n8n1.example.com
n8n2/home/user/.n8n25682n8n2.example.com

Command to create data directories:

mkdir -p /home/user/.n8n
mkdir -p /home/user/.n8n1
mkdir -p /home/user/.n8n2

5️⃣ Systemd Service Definition

Define independent service files in /etc/systemd/system/ for reliable startup, restart, and user management for each instance. Use sudo nano /etc/systemd/system/n8n.service (and similarly for n8n1/n8n2) to create these files.

Service Configuration: n8n.service

[Unit]
Description=n8n workflow automation
After=network.target

[Service]
ExecStart=/usr/local/bin/n8n
Restart=always
User=user
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
Environment=N8N_PORT=5678
Environment=N8N_HOST=n8n.example.com
Environment=N8N_PROTOCOL=https
Environment=N8N_WEBHOOK_URL=https://n8n.example.com/
Environment=N8N_EDITOR_BASE_URL=https://n8n.example.com
Environment=N8N_USER_FOLDER=/home/user/.n8n
WorkingDirectory=/home/user

[Install]
WantedBy=multi-user.target

Service Configuration: n8n1.service

[Unit]
Description=n8n (second instance)
After=network.target

[Service]
ExecStart=/usr/local/bin/n8n
Restart=always
User=user
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
Environment=N8N_PORT=5680
Environment=N8N_HOST=n8n1.example.com
Environment=N8N_PROTOCOL=https
Environment=N8N_WEBHOOK_URL=https://n8n1.example.com/
Environment=N8N_EDITOR_BASE_URL=https://n8n1.example.com
Environment=N8N_USER_FOLDER=/home/user/.n8n1
WorkingDirectory=/home/user

[Install]
WantedBy=multi-user.target

Service Configuration: n8n2.service

[Unit]
Description=n8n (third instance)
After=network.target

[Service]
ExecStart=/usr/local/bin/n8n
Restart=always
User=user
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
Environment=N8N_PORT=5682
Environment=N8N_HOST=n8n2.example.com
Environment=N8N_PROTOCOL=https
Environment=N8N_WEBHOOK_URL=https://n8n2.example.com/
Environment=N8N_EDITOR_BASE_URL=https://n8n2.example.com
Environment=N8N_USER_FOLDER=/home/user/.n8n2
WorkingDirectory=/home/user

[Install]
WantedBy=multi-user.target

6️⃣ Enable and Start Services

Apply the new systemd configurations and activate the services.

sudo systemctl daemon-reload
sudo systemctl enable n8n
sudo systemctl enable n8n1
sudo systemctl enable n8n2
sudo systemctl start n8n
sudo systemctl start n8n1
sudo systemctl start n8n2

Monitor logs for initial startup confirmation (use Ctrl+C to exit):

journalctl -u n8n1 -f

7️⃣ Nginx Reverse Proxy and SSL Setup

Configure Nginx to proxy external traffic to the correct internal ports (5678, 5680, 5682). Create this configuration file for **each domain**.

Example Nginx Server Block: n8n1.example.com.conf

server {
    server_name n8n1.example.com;

    location / {
        proxy_pass http://127.0.0.1:5680;
        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;
    }
}

Activate the configuration and reload Nginx:

sudo ln -s /etc/nginx/sites-available/n8n1.example.com.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

Acquire SSL Certificate using Certbot:

sudo certbot –nginx -d n8n1.example.com

8️⃣ Prerequisite: DNS Configuration

Confirmation of required **A records** is essential prior to Nginx configuration and SSL issuance. Ensure all subdomains point to the server’s public IP address.

Required DNS Records:

TypeNameValue (Server IP)
An8nyour-server-ip
An8n1your-server-ip
An8n2your-server-ip

9️⃣ Individual Instance Reset Procedure

To perform a factory reset, deleting all persistent data (workflows, credentials, users) and forcing the initial “Create Account” screen to reappear:

Resetting Instance: n8n1

sudo systemctl stop n8n1
sudo rm -rf /home/user/.n8n1 # WARNING: This command permanently deletes all instance data.
sudo mkdir -p /home/user/.n8n1
sudo chown -R user:user /home/user/.n8n1
sudo systemctl start n8n1

Access after reset: https://n8n1.example.com

10️⃣ Command Management Reference

Quick reference for common service management commands, using n8n1 as the service example.

ActionCommand
Restart instancesudo systemctl restart n8n1
Stop instancesudo systemctl stop n8n1
View logs (real-time)journalctl -u n8n1 -f
Delete all instance datasudo rm -rf /home/user/.n8n1/*
Check Nginx config syntaxsudo nginx -t
Reload Nginxsudo systemctl reload nginx
Enable automated SSL renewalsudo systemctl enable certbot.timer

Deployment Summary

Three fully isolated and managed n8n instances are configured:

InstanceData FolderInternal PortUserDomain
n8n/home/user/.n8n5678usern8n.example.com
n8n1/home/user/.n8n15680usern8n1.example.com
n8n2/home/user/.n8n25682usern8n2.example.com

Each instance is running under its own systemd service, isolated by data directories and port, and accessible via HTTPS.

4 thoughts on “Multi-Instance n8n Deployment Guide on Ubuntu”

Leave a Comment

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

Breaking: Major Update Just In!

We’ve just rolled out something new. Click below to see what’s changing and how it benefits you.