Skip to content

How to Self-Host n8n on a VPS

n8n runs workflows, integrations and scheduled automations. Self-hosting gives you control over configuration and data, but you are responsible for security, upgrades and backups. This guide runs a single-instance n8n behind Nginx on Ubuntu 24.04.

Requirements: a VPS capable of running Docker containers, a domain such as automation.example.com, and SSH/sudo access. For heavier AI workflows and task runners, budget additional RAM and vCPU beyond the n8n process itself.

Complete the Docker on Ubuntu VPS guide first. Confirm:

Terminal window
sudo docker compose version
Terminal window
sudo mkdir -p /opt/n8n
cd /opt/n8n
sudo sh -c 'umask 077; printf "N8N_HOST=automation.example.com\nN8N_ENCRYPTION_KEY=%s\n" "$(openssl rand -hex 32)" > .env'

Edit .env and replace automation.example.com with your real DNS name. Back up the encryption key securely: losing it can make saved credentials unreadable.

Create /opt/n8n/compose.yaml:

services:
n8n:
image: docker.n8n.io/n8nio/n8n:latest
restart: unless-stopped
ports:
- "127.0.0.1:5678:5678"
environment:
- N8N_HOST=${N8N_HOST}
- N8N_PROTOCOL=https
- N8N_PORT=5678
- WEBHOOK_URL=https://${N8N_HOST}/
- N8N_EDITOR_BASE_URL=https://${N8N_HOST}/
- N8N_PROXY_HOPS=1
- N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
- GENERIC_TIMEZONE=Europe/Kyiv
- TZ=Europe/Kyiv
volumes:
- n8n_data:/home/node/.n8n
volumes:
n8n_data:

Use a tested, pinned n8n image version in production instead of a floating tag. n8n_data contains settings and the default database.

Terminal window
cd /opt/n8n
sudo docker compose up -d
sudo docker compose ps
sudo docker compose logs --tail=30

Install Nginx, point automation.example.com to the VPS and configure the proxy:

server {
listen 80;
server_name automation.example.com;
location / {
proxy_pass http://127.0.0.1:5678;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}

Verify the Nginx config with sudo nginx -t, then obtain a valid TLS certificate using Certbot. Do not expose n8n’s management UI on the public internet without HTTPS and account protection.

Visit https://automation.example.com/, create the owner account, enable 2FA if offered, and test a basic manual workflow.

Terminal window
cd /opt/n8n
sudo docker compose ps
sudo docker compose logs --tail=50

Before updates, back up both the n8n volume and .env securely; use tested restore procedures. Then change to a reviewed n8n version and run sudo docker compose pull && sudo docker compose up -d. Monitor release notes for migration changes.

Official reference: n8n Docker Compose documentation.


Need a VPS for this project? Compare ProstoHosting VPS plans.