Building your own automation server is easier than you think.
In this tutorial, we’ll deploy n8n — a powerful open-source automation tool — on an Ubuntu 22.04 server using Docker, Nginx, and Let’s Encrypt SSL, complete with WebSocket support and production-ready configuration.
🧭 n8n Self-Hosting Guide (Ubuntu Server)
Server Specs: 1 GB RAM | 1 Core | 40 GB SSD
OS: Ubuntu 22.04 +
🚀 1. Update Server and Install Docker
sudo apt update && sudo apt upgrade -y
sudo apt install -y docker.io docker-compose nginx certbot python3-certbot-nginx
sudo systemctl enable docker
sudo systemctl start docker
📁 2. Create Project Directory
mkdir -p ~/n8n/data
cd ~/n8n
🧩 3. Create docker-compose.yml
version: "3.3"
services:
n8n:
image: n8nio/n8n:latest
container_name: n8n
restart: unless-stopped
ports:
- "5678:5678"
volumes:
- ./data:/home/node/.n8n
environment:
- NODE_ENV=production
- GENERIC_TIMEZONE=Asia/Kolkata
- TZ=Asia/Kolkata
- N8N_HOST=n8n.yourdomain.in
- N8N_PORT=5678
- N8N_PROTOCOL=https
- WEBHOOK_URL=https://n8n.yourdomain.in/
- N8N_BASIC_AUTH_ACTIVE=true
- N8N_BASIC_AUTH_USER=admin
- N8N_BASIC_AUTH_PASSWORD=my_pass
- N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
- DB_SQLITE_POOL_SIZE=2
- N8N_RUNNERS_ENABLED=true
- N8N_BLOCK_ENV_ACCESS_IN_NODE=false
- N8N_GIT_NODE_DISABLE_BARE_REPOS=true
- N8N_PROXY_HOPS=1
- N8N_TRUSTED_PROXIES=loopback,linklocal,uniquelocal
- N8N_ENCRYPTION_KEY=--KEY--GENERATED-BY-USER---
- EXECUTIONS_DATA_PRUNE=true
- EXECUTIONS_DATA_MAX_AGE=90
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
Save → Ctrl + O, Enter, Ctrl + X.
🔐 4. Fix Folder Permissions
cd ~/n8n
sudo chown -R 1000:1000 data
sudo chmod -R 755 data
▶️ 5. Start n8n Container
sudo docker-compose up -d
Verify:
sudo docker ps
Expected output:
CONTAINER ID IMAGE STATUS PORTS NAMES
xxxxxx n8nio/n8n Up 10 seconds 0.0.0.0:5678->5678/tcp n8n
🌐 6. Configure Nginx Reverse Proxy (With WebSocket Support)
Create file:
sudo nano /etc/nginx/sites-available/n8n.conf
Paste:
server {
listen 80;
server_name n8n.yourdomain.in;
location / {
proxy_pass http://127.0.0.1:5678/;
proxy_http_version 1.1;
# --- WebSocket Support ---
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# --- Standard Headers ---
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;
# --- Timeouts for long workflows ---
proxy_read_timeout 600s;
proxy_send_timeout 600s;
proxy_connect_timeout 600s;
# --- Disable buffering ---
proxy_buffering off;
proxy_cache off;
}
}
Enable and reload:
sudo ln -s /etc/nginx/sites-available/n8n.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
🔒 7. Enable HTTPS (SSL via Let’s Encrypt)
sudo certbot --nginx -d n8n.yourdomain.in
sudo certbot renew --dry-run
Now visit 👉 https://n8n.yourdomain.in
⚙️ 8. Manage Container
sudo docker-compose restart # Restart
sudo docker-compose down # Stop
sudo docker logs n8n --tail 50 # View logs
🧱 9. Auto-Start on Reboot
sudo systemctl enable docker
✅ 10. Verification Checklist
| Check | Command | Expected |
|---|---|---|
| Docker running | sudo systemctl status docker |
active (running) |
| Container up | sudo docker ps |
STATUS = Up |
| Nginx config OK | sudo nginx -t |
syntax is ok |
| SSL active | Browser | padlock icon |
🧾 11. Summary
| Component | Status |
|---|---|
| Docker installed | ✅ |
| n8n container healthy | ✅ |
| HTTPS via Nginx & Certbot | ✅ |
Data persisted in ~/n8n/data |
✅ |
| Auto-restart on reboot | ✅ |
💡 Notes
- Keep
N8N_ENCRYPTION_KEYsecret — it secures stored credentials. - Back up
~/n8n/dataregularly. - Avoid sharing passwords or logs publicly.
- If you deploy more apps, give each a unique domain + port.
Hosting n8n yourself gives you full control over your automation stack — no vendor limits, no API throttling, and complete privacy. With Docker + Nginx + Let’s Encrypt, you’re now running a production-grade, SSL-secured, WebSocket-enabled n8n instance that can scale effortlessly on any VPS or cloud server.