How to Self-Host n8n on a VPS (Complete Guide)
In todayโs world, automation is key to improving productivity, and n8n is an excellent open-source workflow automation tool that lets you connect different apps and services without needing to write code. Self-hosting n8n on a Virtual Private Server (VPS) is a good option for developers looking for control and customization of their data flows. This guide covers the steps to install and configure n8n using Docker on a VPS.
Prerequisites
- Choose a VPS Provider: Select a VPS provider that fits your needs. Hereโs a comparison of some popular options:
| Provider | Price (per month) | RAM | Storage |
|---|---|---|---|
| Contabo VPS | 5.99 EUR | 4 GB | 200 GB SSD |
| Hetzner Cloud | 4.15 EUR | 2 GB | 20 GB SSD |
| DigitalOcean | 6 USD | 1 GB | 25 GB SSD |
| Vultr | 6 USD | 1 GB | 25 GB SSD |
| Linode (Akamai) | 5 USD | 2 GB | 50 GB SSD |
-
Install Docker: Ensure that Docker and Docker Compose are installed on your VPS. If they are not installed, you can follow the official Docker installation guide.
-
Secure Your Server: A basic firewall configuration with
ufw(Uncomplicated Firewall) is recommended. This should include allowing SSH and the necessary ports for n8n.
Step 1: Set Up Docker
After logging in to your VPS via SSH, verify that Docker is installed by running:
docker --version
If Docker is not installed, you can install it using:
sudo apt update
sudo apt install docker.io
Enable and start Docker:
sudo systemctl enable docker
sudo systemctl start docker
Step 2: Create n8n Directory
Create a directory for n8n and navigate into it:
mkdir ~/n8n
cd ~/n8n
Step 3: Create Docker Compose File
Create a new docker-compose.yml file with your preferred text editor:
nano docker-compose.yml
Add the following configuration:
version: '3'
services:
n8n:
image: n8nio/n8n
environment:
- N8N_API_BASIC_AUTH_ACTIVE=true
- N8N_API_BASIC_AUTH_USER=user
- N8N_API_BASIC_AUTH_PASSWORD=your_password
- N8N_HOST=your_domain_or_ip
- N8N_PORT=5678
- N8N_PROTOCOL=https
- N8N_SSL_CERT=your_ssl_cert_path
- N8N_SSL_KEY=your_ssl_key_path
volumes:
- ~/.n8n:/home/node/.n8n
ports:
- "5678:5678"
restart: always
Replace your_domain_or_ip, your_ssl_cert_path, and your_ssl_key_path with your information. You can use Letโs Encrypt for SSL (more on this later).
Step 4: Run n8n
Start n8n using Docker Compose:
docker-compose up -d
Verify that n8n is running by checking if the container is active:
docker ps
Step 5: Access n8n
You can access your n8n instance using your VPS IP or domain name:
http://your_domain_or_ip:5678
Log in with the credentials you specified in the docker-compose.yml.
Step 6: Configure SSL (Optional but Recommended)
For enhanced security, it is a good practice to set up SSL. You can use Letโs Encrypt:
-
Install Certbot:
sudo apt install certbot -
Get Certificates:
sudo certbot certonly --standalone -d your_domain.com -
Update the
docker-compose.ymlfile to include the correct SSL certificate paths as shown in Step 3.
After updating, restart the n8n services:
docker-compose down
docker-compose up -d
FAQs
1. What are the benefits of self-hosting n8n over using the cloud version?
Self-hosting n8n offers numerous benefits, including complete data control, customizable features according to specific needs, and more flexible automation possibilities by connecting with other self-hosted services. You can ensure that sensitive data remains private and comply with data protection regulations as you dictate how and where the data is processed. Ultimately, self-hosting also allows for experimenting with more integrations without potential usage limits typically imposed on cloud versions.
2. Can I run n8n on a low-tier VPS?
Yes, n8n can run on low-tier VPS, but performance may vary based on the complexity of the workflows you plan to execute. For simple automations, options like Hetzner Cloud or DigitalOcean with at least 1-2 GB of RAM should suffice. However, for heavier workflows that require storing larger data sets or running many simultaneous executions, you may need a more robust VPS setup, possibly with additional RAM and CPU.
3. How to backup n8n configurations and data?
Backing up n8n configurations and data is vital for ensuring the continuity of your workflows. Since n8n stores its data in the volume you mounted (as specified in the docker-compose.yml), you should regularly back up the ~/.n8n directory. This can be achieved by copying it to another location, scheduled via cron jobs, or by using backup services. Automating backups of this directory to cloud storage or another physical server aids in minimizing data loss and maintaining system resilience.
By following this complete guide, you will be well-prepared to self-host n8n on your VPS, tapping into its potential for automating workflows effectively. For comparisons of the best VPS providers, visit our full VPS comparison. Happy self-hosting!