How to Self-Host n8n on Ubuntu: A Step-by-Step Guide
Author: Wally
Published on
May 29, 2025
n8n is a powerful, extendable workflow automation tool that you can self-host for full control and customization. This guide will walk you through installing and configuring n8n on an Ubuntu server.
Prerequisites
Before starting, make sure you have:
- An Ubuntu 20.04 or newer server (VPS or local machine). I will use 24.04 as a demo
- Root or sudo access
- A domain name pointing to your server's IP (e.g.,
n8n.example.com
) - Docker and Docker Compose installed
Step 1: Update Your System
sudo apt update && sudo apt upgrade -y
Step 2: Install Docker and Docker Compose
Skip this step if you have Docker installed
sudo apt install -y docker.io docker-compose
sudo systemctl enable docker
sudo systemctl start docker
Verify installation:
docker --version
docker-compose --version
Step 3: Create Docker Setup for n8n
Create a directory for n8n:
Create a .env
file:
Add environment variables (edit for your domain):
N8N_HOST=n8n.example.com
N8N_PORT=5678
N8N_PROTOCOL=https
WEBHOOK_URL=https://n8n.example.com/
Create docker-compose.yml
:
version: "3"
services:
n8n:
image: n8nio/n8n
restart: always
ports:
- "5678:5678"
environment:
- GENERIC_TIMEZONE=Australia/Sydney
- N8N_BASIC_AUTH_ACTIVE=true
- N8N_PUSH_BACKEND=websocket
- N8N_HOST=${N8N_HOST}
- N8N_PORT=${N8N_PORT}
- N8N_PROTOCOL=${N8N_PROTOCOL}
- WEBHOOK_URL=${WEBHOOK_URL}
volumes:
- ~/.n8n:/home/node/.n8n
Step 4: Start n8n
You should now be able to access n8n at:
http://your-server-ip:5678 or https://n8n.example.com (once SSL is configured)
Step 5: Set Up (Apache)
Skip to Step 6 if you already have Apache installed
Install Apache:
sudo apt update
sudo apt install apache2 -y
Start Apache & Enable the Apache service to start automatically at boot time.:
sudo systemctl start apache2
sudo systemctl enable apache2
Check Apache Status:
sudo systemctl status apache2
Allow connections to the HTTP port 80 through the default firewall configuration:
Step 6: Create a new Apache Virtual Host for n8n
Create a new Apache configuration file for n8n:
sudo nano /etc/apache2/sites-available/n8n.conf
Paste the configuration below into the file. This will be your reverse proxy for n8n and redirect user to n8n hosted from docker on port 5678 when they access https://n8n.example.com
<VirtualHost *:80>
ServerName n8n.example.com
ProxyPreserveHost On
ProxyRequests Off
# WebSocket proxy for n8n real-time push
ProxyPass "/rest/push" "ws://127.0.0.1:5678/rest/push"
ProxyPassReverse "/rest/push" "ws://127.0.0.1:5678/rest/push"
# Usual HTTP proxy for everything else
ProxyPass "/" "http://localhost:5678/"
ProxyPassReverse "/" "http://localhost:5678/"
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/n8n/(.*)$
RewriteRule ^/n8n/(.*)$ /$1 [L,P]
ErrorLog ${APACHE_LOG_DIR}/n8n-error.log
CustomLog ${APACHE_LOG_DIR}/n8n-access.log combined
</VirtualHost>
Disable the default Apache virtual host configuration:
sudo a2dissite 000-default
Enable the new Apache virtual host configuration:
Test the Apache configuration for errors. It will tell you whether the syntax is ok or not
sudo apachectl configtest
Restart the Apache web server to apply your configuration changes:
sudo systemctl restart apache2
Step 6: Set Up SSL (Let's Encrypt)
Install the Certbot Let's Encrypt client package using the Snap package manager:
sudo snap install certbot --classic
Request a new Let's Encrypt SSL certificate on your server using your virtual host domain. Replace app.example.com with your actual domain and hello@example.com with your email address.
sudo certbot --apache --agree-tos --redirect -d app.example.com -m hello@example.com
Test the Certbot SSL certificate renewal process:
sudo certbot renew --dry-run
Restart the Apache web server to apply your SSL configuration changes.
sudo systemctl restart apache2
Done!
You’ve successfully self-hosted n8n on Ubuntu. You can now start building workflows securely from your own server.
For additional security:
- Use HTTPS and strong passwords
- Set up firewall rules
- Backup your workflows regularly
Happy automating 🚀
Back to Blogs