How to Self-Host n8n on a VPS
Why self-host n8n?
Section titled “Why self-host n8n?”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.
1. Install Docker
Section titled “1. Install Docker”Complete the Docker on Ubuntu VPS guide first. Confirm:
sudo docker compose version2. Create a persistent n8n stack
Section titled “2. Create a persistent n8n stack”sudo mkdir -p /opt/n8ncd /opt/n8nsudo 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/.n8nvolumes: n8n_data:Use a tested, pinned n8n image version in production instead of a floating tag. n8n_data contains settings and the default database.
cd /opt/n8nsudo docker compose up -dsudo docker compose pssudo docker compose logs --tail=303. Add Nginx and HTTPS
Section titled “3. Add Nginx and HTTPS”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.
4. Test, update and back up
Section titled “4. Test, update and back up”Visit https://automation.example.com/, create the owner account, enable 2FA if offered, and test a basic manual workflow.
cd /opt/n8nsudo docker compose pssudo docker compose logs --tail=50Before 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.