How to Install n8n on Your SNBD HOST VPS
This guide provides step-by-step instructions on how to install and set up n8n, the open-source workflow automation tool, on your SNBD HOST Virtual Private Server (VPS) using Docker and Docker Compose.
Self-hosting n8n on your SNBD HOST VPS gives you complete control over your automation workflows and data. This tutorial will walk you through the recommended method of installing n8n using Docker and Docker Compose.
Prerequisites
Before you begin, ensure you have the following:
- An active SNBD HOST VPS or Cloud Server with a fresh installation of Ubuntu (or a similar Linux distribution).
- SSH access to your VPS with root privileges or a user with
sudoaccess. - Basic familiarity with the Linux command line.
- A domain name pointed to your VPS IP address (optional, but recommended for easy access and SSL).
Step 1: Connect to Your VPS via SSH
First, you need to connect to your SNBD HOST VPS using an SSH client. Replace your_username and your_vps_ip with your actual credentials.
ssh your_username@your_vps_ip
If you are logging in as root, use ssh root@your_vps_ip.
Step 2: Update Your System
It's always a good practice to update your system's package list and upgrade existing packages to their latest versions.
sudo apt update && sudo apt upgrade -y
Step 3: Install Docker and Docker Compose
n8n is best run in a Docker container for ease of deployment and management. Docker Compose simplifies the setup of multi-container Docker applications.
Install Docker:
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io -y
Verify Docker installation:
sudo docker run hello-world
Install Docker Compose:
sudo curl -L "https://github.com/docker/compose/releases/download/v2.20.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
Verify Docker Compose installation:
docker-compose --version
Step 4: Create a Directory for n8n
Create a dedicated directory for your n8n installation and navigate into it. This is where your docker-compose.yml file and n8n data will reside.
mkdir ~/.n8n
cd ~/.n8n
Step 5: Create a docker-compose.yml File
Create a docker-compose.yml file using a text editor like nano.
nano docker-compose.yml
Paste the following content into the file. This configuration sets up n8n to run on port 5678 and persists its data in a Docker volume.
version: '3.8'
services:
n8n:
image: n8nio/n8n
restart: always
ports:
- "5678:5678"
environment:
- N8N_HOST=${N8N_HOST:-localhost}
- N8N_PORT=5678
- N8N_PROTOCOL=${N8N_PROTOCOL:-http}
- WEBHOOK_URL=${WEBHOOK_URL:-http://localhost:5678/}
- GENERIC_TIMEZONE=${GENERIC_TIMEZONE:-Asia/Dhaka} # Example: Set your timezone
volumes:
- ~/.n8n/data:/home/node/.n8n
Explanation of variables:
ports: - "5678:5678": This maps port5678on your VPS to port5678inside the n8n Docker container. You will access n8n viahttp://your_vps_ip:5678.volumes: - ~/.n8n/data:/home/node/.n8n: This creates a persistent volume for n8n's data, ensuring your workflows and credentials are saved even if the container is restarted or updated.GENERIC_TIMEZONE: It's highly recommended to set your timezone, e.g.,Asia/Dhakafor Bangladesh.N8N_HOST,N8N_PROTOCOL,WEBHOOK_URL: These are important for n8n to generate correct webhook URLs. For initial setup,localhostis fine. If you plan to use a domain with SSL, you'll update these later (see Step 8).
Save and exit the file (Ctrl+X, Y, Enter in nano).
Step 6: Start n8n
Now, start the n8n container using Docker Compose from within the ~/.n8n directory:
docker-compose up -d
up: Starts the services defined indocker-compose.yml.-d: Runs the containers in detached mode (in the background).
It might take a few moments for n8n to download the image and start up.
Step 7: Access n8n Web Interface
Open your web browser and navigate to http://your_vps_ip:5678 (replace your_vps_ip with your VPS's public IP address).
You should see the n8n setup screen, where you can create your first user account. Follow the on-screen instructions to complete the initial setup.
Step 8: (Optional) Set up a Reverse Proxy with Nginx and Let's Encrypt SSL
For production use, it's highly recommended to access n8n via a domain name with SSL (HTTPS). This provides security and a more professional URL. SNBD HOST's shared hosting includes Let's Encrypt SSL, and you can easily set it up on your VPS too.
8.1 Install Nginx:
sudo apt install nginx -y
8.2 Configure Nginx:
Create a new Nginx configuration file for your domain:
sudo nano /etc/nginx/sites-available/your_domain.com
Paste the following content, replacing your_domain.com with your actual domain:
server {
listen 80;
server_name your_domain.com www.your_domain.com;
location / {
proxy_pass http://localhost:5678;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
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;
}
}
Save and exit the file.
8.3 Enable the Nginx Configuration:
Create a symbolic link to enable the site and test Nginx configuration:
sudo ln -s /etc/nginx/sites-available/your_domain.com /etc/nginx/sites-enabled/
sudo nginx -t
If the test is successful, restart Nginx:
sudo systemctl restart nginx
8.4 Install Certbot for Let's Encrypt SSL:
sudo apt install certbot python3-certbot-nginx -y
8.5 Obtain and Install SSL Certificate:
sudo certbot --nginx -d your_domain.com -d www.your_domain.com
Follow the prompts. Certbot will automatically configure Nginx for HTTPS.
8.6 Update n8n Docker Compose Environment Variables:
Now that you have HTTPS, you need to update your docker-compose.yml to reflect the correct WEBHOOK_URL and N8N_PROTOCOL.
cd ~/.n8n
nano docker-compose.yml
Modify the environment section to use https and your domain:
environment:
- N8N_HOST=your_domain.com
- N8N_PORT=5678
- N8N_PROTOCOL=https
- WEBHOOK_URL=https://your_domain.com/
- GENERIC_TIMEZONE=${GENERIC_TIMEZONE:-Asia/Dhaka}
Save and exit. Then, restart your n8n container to apply changes:
docker-compose down
docker-compose up -d
Now you can access your n8n instance securely via https://your_domain.com.
Congratulations! You have successfully installed n8n on your SNBD HOST VPS and secured it with SSL.