π Install Self-Hosted n8n on Linux EC2 with Domain & SSL
n8n is a powerful workflow automation tool, similar to Zapier, but open-source and self-hosted. In this guide, weβll install n8n on a Linux EC2 instance, configure it with a custom domain, and secure it using SSL certificates via Letβs Encrypt.
β Prerequisites
- An AWS EC2 Instance (Ubuntu 22.04 recommended)
- Domain name (already purchased)
- Port 80 and 443 open in EC2 Security Group
- Basic SSH access to your server
π₯ Step 1: Connect to Your EC2 Instance
ssh -i your-key.pem ubuntu@your-ec2-public-ip
π¦ Step 2: Update Server & Install Dependencies
sudo apt update && sudo apt upgrade -y
sudo apt install -y docker.io docker-compose certbot python3-certbot-nginx
π Step 3: Create n8n Docker Setup
Create a new folder for n8n:
mkdir ~/n8n && cd ~/n8n
Create a docker-compose.yml
file:
nano docker-compose.yml
Paste the following content:
version: '3.3'
services:
n8n:
image: n8nio/n8n
restart: always
ports:
- "5678:5678"
environment:
- N8N_BASIC_AUTH_ACTIVE=true
- N8N_BASIC_AUTH_USER=admin
- N8N_BASIC_AUTH_PASSWORD=strongpassword
- N8N_HOST=n8n.yourdomain.com
- N8N_PORT=5678
- N8N_PROTOCOL=https
volumes:
- ~/.n8n:/home/node/.n8n
Save & exit (CTRL+X
, Y
, Enter
).
π Step 4: Setup Reverse Proxy with Nginx
sudo apt install -y nginx
sudo nano /etc/nginx/sites-available/n8n
Paste the following config (replace n8n.yourdomain.com
):
server {
server_name n8n.yourdomain.com;
location / {
proxy_pass http://localhost:5678;
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;
}
}
Enable the site & restart Nginx:
sudo ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
π Step 5: Secure with Letβs Encrypt SSL
sudo certbot --nginx -d n8n.yourdomain.com
β
Follow prompts, enter your email, and Certbot will install SSL automatically.
π Step 6: Start n8n
cd ~/n8n
docker-compose up -d
Now visit: https://n8n.yourdomain.com π
π‘ Security Notes
- Change
N8N_BASIC_AUTH_USER
andN8N_BASIC_AUTH_PASSWORD
in yourdocker-compose.yml
. - Regularly update n8n with:
docker-compose pull && docker-compose up -d
- Renew SSL automatically:
sudo systemctl enable certbot.timer
π― Conclusion
Youβve successfully installed self-hosted n8n on an EC2 instance, secured it with SSL, and mapped it to your custom domain. Now you can start building automation workflows like a pro!