Hosting
Servers
Web Development Pricing
Resources
Get started → Log in
Home/Blog/n8n self-hosting on a VPS

n8n self-hosting on a VPS:
Docker, Postgres and HTTPS.

27 November 20269 min readBy the RapidServer team

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 VPSn8n Cloud
Who runs itYou, on your own servern8n hosts it for you
SetupDocker, a domain and HTTPSSign up, no installation
Updates and maintenanceYour jobHandled by n8n
ControlFull: environment variables, custom nodes, server locationLimited to the options n8n offers
LicenceFree Community edition, or paid licence keysPaid 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:

shell
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:

.env
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:

compose.yaml
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.

VariableSet toWhat it does
N8N_HOSTn8n.example.comThe hostname n8n runs on, without https://
N8N_PORT5678The HTTP port n8n listens on; 5678 is the default
N8N_WEBHOOK_URLhttps://n8n.example.com/The public webhook address behind a reverse proxy; before n8n 2.30.0 it was WEBHOOK_URL
N8N_PROXY_HOPS1Tells n8n it sits behind one reverse proxy
N8N_ENCRYPTION_KEYYour random keyEncrypts saved credentials in the database
GENERIC_TIMEZONEAsia/KolkataThe timezone Schedule nodes use; the default is America/New_York
TZAsia/KolkataSystem 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:

/etc/caddy/Caddyfile
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:

nginx server block
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 to 127.0.0.1 and 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_KEY in a password manager, off the server; without it, restored credentials can't be decrypted. Run chmod 600 .env and 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:

backup
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:

update
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

UsePlanPer month
Trying n8n, or a few light workflowsStardust: 2 vCPU, 4 GB RAM, 20 GB NVMe₹581
n8n with Postgres for a small teamNew Moon: 2 vCPU, 4 GB RAM, 40 GB NVMe₹674
Busy instances, large files or AI agent workflowsFull 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.

Host n8n on a KVM VPS in India.

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 plans

Questions

Is n8n free to self-host?+
Yes. The Community edition is free to self-host under n8n's Sustainable Use License, for internal business or personal use, so you pay only for the server. Paid Business and Enterprise licence keys unlock features such as SSO.
What are the n8n self-hosted requirements?+
A 64-bit Linux server, Docker Engine with the Docker Compose v2 plugin, PostgreSQL for production, a subdomain pointing at the server and a reverse proxy for HTTPS. For a small team, 2 vCPU and 4 GB RAM is a comfortable start.
Should I use WEBHOOK_URL or N8N_WEBHOOK_URL?+
Use 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/.
What happens if I lose N8N_ENCRYPTION_KEY?+
n8n can no longer decrypt the credentials saved in its database, so you would have to enter every API key and login again. Keep a copy of the key off the server and back up the n8n data volume with the database.
Should I choose self-hosted n8n or n8n Cloud?+
n8n Cloud suits you if you don't want to run a server. Self-host if you want full control, custom nodes, your choice of server location and the free Community edition, and can look after Linux, backups and updates.
n8n ko VPS par self host kaise karein?+
Ek Linux KVM VPS lijiye, usme Docker Compose se n8n aur PostgreSQL chalaiye, Caddy ya Nginx se HTTPS lagaiye aur timezone Asia/Kolkata rakhiye, taaki schedules Indian time par chalein. RapidServer par VPS ₹581/mo plus 18% GST se shuru hota hai aur payment ke kuch minute baad ready ho jata hai.
How much does n8n VPS hosting cost in India?+
Self-hosted n8n costs only the server. A RapidServer VPS starts at ₹581/mo, and New Moon with 40 GB NVMe costs ₹674/mo, plus 18% GST, billed monthly with daily backups kept for 7 days.

Self-host n8n on a VPS in India.

KVM VPS with dedicated vCPU, NVMe and full root in Mumbai or Delhi NCR, billed monthly in rupees with a GST invoice.