How do you self-host n8n on a VPS?
Rent a 64-bit Linux KVM VPS with Docker, point a subdomain such as n8n.example.com at its IP address, and run n8n with PostgreSQL in Docker Compose. Keep n8n on port 5678 on localhost and put Caddy or Nginx in front for free Let's Encrypt HTTPS. Set N8N_HOST, N8N_WEBHOOK_URL, N8N_ENCRYPTION_KEY and the Asia/Kolkata timezone, then back up the database and the n8n data volume, and update every month.
Below is each step on a RapidServer KVM VPS with full root in Mumbai (BOM1) or Delhi NCR (DEL1).
What is n8n?
n8n is a workflow automation tool that combines AI features with business process automation. You build workflows on a visual canvas from nodes: a trigger, such as a webhook or a schedule, starts the workflow, and later nodes call APIs, transform data or send a Slack or email alert. Webhooks must be reachable from the internet and schedules must fire on time, so n8n needs a server that stays online.
Licence. n8n uses the Sustainable Use License, which it calls fair-code, not open source. You may use and modify n8n for your own internal business purposes or for personal and non-commercial use. Offering n8n itself to your customers, so they connect their own accounts and build workflows, needs a commercial agreement with n8n. Building workflows for clients as a consultant is allowed.
Self-hosted n8n vs n8n Cloud
The main difference is who runs the server (n8n's own comparison):
| Self-hosted on a VPS | n8n Cloud | |
|---|---|---|
| Who runs it | You, on your own server | n8n hosts it for you |
| Setup | Docker, a domain and HTTPS | Sign up, no installation |
| Updates and maintenance | Your job | Handled by n8n |
| Control | Full: environment variables, custom nodes, server location | Limited to the options n8n offers |
| Licence | Free Community edition, or paid licence keys | Paid plans after a free trial |
n8n itself recommends its Cloud to people without server experience. Self-host if you know Linux and want control over the setup and where your data lives.
n8n self-hosted requirements
From n8n's production requirements:
- A 64-bit Linux server, such as Ubuntu LTS, on KVM: container-based VPS often cannot run Docker.
- Docker Engine and the Docker Compose v2 plugin. On RapidServer you can pick the ready Docker image when you deploy.
- PostgreSQL for production. n8n starts on SQLite, which suits testing, but doesn't recommend it for multi-user production.
- A subdomain with an A record pointing at your server's IPv4 address. See DNS kya hai.
- A reverse proxy for TLS. n8n says not to expose the n8n process directly to the internet.
- A persistent volume and an encryption key that you store safely.
For a small team, n8n with PostgreSQL usually fits in 4 GB of RAM, where every RapidServer VPS starts. Workflows that move large files or run many jobs at once need more.
n8n self-hosted Docker setup with Postgres
SSH in as root (new to SSH? read SSH kya hai), create a folder and generate an encryption key:
mkdir -p ~/n8n && cd ~/n8n openssl rand -hex 32
Create a .env file with the key, your subdomain, a long random database password and the current stable n8n version:
N8N_VERSION=change-me-stable-version N8N_HOST=n8n.example.com N8N_ENCRYPTION_KEY=change-me-paste-the-openssl-output POSTGRES_USER=n8n POSTGRES_PASSWORD=change-me-long-random-password POSTGRES_DB=n8n
Then create compose.yaml. It follows the shape of n8n's Docker Compose guide and its server example, with Caddy or Nginx on the host in place of Traefik:
services:
postgres:
image: postgres:18
restart: always
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
PGDATA: /var/lib/postgresql/data
volumes:
- db_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -h localhost -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
interval: 5s
timeout: 5s
retries: 10
n8n:
image: n8nio/n8n:${N8N_VERSION}
restart: always
ports:
- "127.0.0.1:5678:5678"
environment:
DB_TYPE: postgresdb
DB_POSTGRESDB_HOST: postgres
DB_POSTGRESDB_PORT: "5432"
DB_POSTGRESDB_DATABASE: ${POSTGRES_DB}
DB_POSTGRESDB_USER: ${POSTGRES_USER}
DB_POSTGRESDB_PASSWORD: ${POSTGRES_PASSWORD}
N8N_HOST: ${N8N_HOST}
N8N_PORT: "5678"
N8N_PROTOCOL: https
N8N_WEBHOOK_URL: https://${N8N_HOST}/
N8N_PROXY_HOPS: "1"
N8N_ENCRYPTION_KEY: ${N8N_ENCRYPTION_KEY}
GENERIC_TIMEZONE: Asia/Kolkata
TZ: Asia/Kolkata
volumes:
- n8n_data:/home/node/.n8n
depends_on:
postgres:
condition: service_healthy
volumes:
db_data:
n8n_data:
Start it with docker compose up -d and watch the logs with docker compose logs -f n8n. Keep the PGDATA line: n8n warns that without it Postgres 18 writes outside the volume and your database starts empty.
The environment variables that matter
Full lists are in n8n's deployment, endpoints and database references.
| Variable | Set to | What it does |
|---|---|---|
N8N_HOST | n8n.example.com | The hostname n8n runs on, without https:// |
N8N_PORT | 5678 | The HTTP port n8n listens on; 5678 is the default |
N8N_WEBHOOK_URL | https://n8n.example.com/ | The public webhook address behind a reverse proxy; before n8n 2.30.0 it was WEBHOOK_URL |
N8N_PROXY_HOPS | 1 | Tells n8n it sits behind one reverse proxy |
N8N_ENCRYPTION_KEY | Your random key | Encrypts saved credentials in the database |
GENERIC_TIMEZONE | Asia/Kolkata | The timezone Schedule nodes use; the default is America/New_York |
TZ | Asia/Kolkata | System time for scripts and commands such as date |
Set N8N_ENCRYPTION_KEY before the first start; otherwise n8n generates its own key and saves it in the data volume. Without the right timezone, a 9 am schedule runs at 9 am New York time.
HTTPS with a reverse proxy: Caddy or Nginx
n8n recommends ending TLS at a reverse proxy. Caddy is the shortest route: install it from its official packages and put this in /etc/caddy/Caddyfile. Caddy gets and renews the Let's Encrypt certificate by itself:
n8n.example.com {
reverse_proxy 127.0.0.1:5678
}
Nginx works too. n8n's reverse proxy guide asks for the X-Forwarded-* headers, and the editor uses WebSockets by default, so pass the upgrade headers too. Then run certbot --nginx -d n8n.example.com:
location / {
proxy_pass http://127.0.0.1:5678;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
}
Security: firewall, owner account and encryption key
- Firewall. Open only SSH, 80 and 443:
ufw allow OpenSSH,ufw allow 80,443/tcp,ufw enable. Ports published by Docker skip ufw rules, so the Compose file binds n8n to127.0.0.1and doesn't publish Postgres. See our firewall guide. - Owner account. Open your URL straight after the first start: on a fresh instance, the first person to finish the setup screen becomes the owner. Use a long, unique password and turn on two-factor authentication.
- Encryption key. Keep a copy of
N8N_ENCRYPTION_KEYin a password manager, off the server; without it, restored credentials can't be decrypted. Runchmod 600 .envand keep it out of git. - SSH keys. Add your public key in the client area so new servers boot with it and password login disabled.
Backups: Postgres dump and the n8n data volume
n8n's backup guide says a complete backup has two parts: the PostgreSQL database, and the .n8n folder in the n8n_data volume, which holds the encryption key. Run this nightly from cron:
cd ~/n8n && mkdir -p backups docker compose exec -T postgres sh -c 'pg_dump -U "$POSTGRES_USER" "$POSTGRES_DB"' > backups/n8n-db-$(date +%F).sql docker compose cp n8n:/home/node/.n8n backups/n8n-data-$(date +%F)
Copy the files off the server and test a restore once: stop n8n, restore the .n8n folder and the database, keep the same .env, then start n8n. Every RapidServer VPS also gets daily backups kept for 7 days, plus snapshots on demand.
Updating self-hosted n8n
n8n releases a new minor version most weeks, and its update guide suggests updating at least once a month after reading the release notes for breaking changes. Take a snapshot and a backup, change N8N_VERSION in .env, then run the Docker Compose update steps:
cd ~/n8n docker compose pull docker compose down docker compose up -d
n8n migrates its database when it starts, and an older image doesn't undo that, so if an update goes wrong, restore the snapshot or backup.
Which VPS plan to pick for n8n
| Use | Plan | Per month |
|---|---|---|
| Trying n8n, or a few light workflows | Stardust: 2 vCPU, 4 GB RAM, 20 GB NVMe | ₹581 |
| n8n with Postgres for a small team | New Moon: 2 vCPU, 4 GB RAM, 40 GB NVMe | ₹674 |
| Busy instances, large files or AI agent workflows | Full Moon: 4 vCPU, 8 GB RAM, 160 GB NVMe | ₹1,723 |
New Moon is the sensible start: the extra NVMe leaves room for execution history, Postgres and Docker images. Every plan has dedicated vCPU and full root, is billed monthly plus 18% GST, and can move up from the client area with the difference prorated. Choose Mumbai (BOM1) or Delhi NCR (DEL1) at the same price; Noida and Gurugram are served from DEL1. Managed support adds ₹1,499/mo; see managed vs unmanaged VPS.
Dedicated vCPU, NVMe, full root and a ready Docker image in Mumbai or Delhi NCR, ready a few minutes after payment, from ₹581/mo.
See VPS plansQuestions
Is n8n free to self-host?+
What are the n8n self-hosted requirements?+
Should I use WEBHOOK_URL or N8N_WEBHOOK_URL?+
N8N_WEBHOOK_URL on n8n 2.30.0 or later. WEBHOOK_URL is the older name: deprecated from 2.35.0, it still works but logs a warning. Set it to your full address, such as https://n8n.example.com/.