Limited Time Offer

20% OFF

On All Shared RDP Plans

Use the code below at checkout and save instantly on any Shared plan.

NEWRDP20
Claim Your Discount

*Valid on Shared Plans only. Limited time offer.

Loader

How to Self-Host n8n on a VPS with Docker, Postgres and HTTPS

A working production-style n8n setup on a Linux VPS: Docker Compose, Postgres, automatic HTTPS and the settings people most often get wrong.

  • Docker Compose + Postgres
  • Automatic HTTPS with Caddy
  • Webhook and encryption-key tips
How to Self-Host n8n on a VPS with Docker, Postgres and HTTPS
  • 22 October 2026
  • by Admin

How to Self-Host n8n on a VPS with Docker, Postgres and HTTPS

Running n8n yourself is not hard, but a casual docker run is not a production setup. This guide builds one you can actually rely on: n8n and Postgres in Docker Compose, a reverse proxy with automatic HTTPS, and the environment variables that keep webhooks and credentials working.

If you would rather skip the server work, managed n8n hosting gives you the same dedicated instance with backups and monitoring handled for you.

What you need

  • A Linux VPS with at least 2 GB of RAM and 1-2 vCPU (Ubuntu 22.04 or 24.04 works well). Browse our Linux VPS plans if you need one.
  • A domain or subdomain, for example n8n.yourdomain.com, with an A record pointing at the VPS IP.
  • SSH access as a user with sudo rights.

Step 1: update the server and install Docker

sudo apt update && sudo apt upgrade -y
curl -fsSL https://get.docker.com | sudo sh
sudo usermod -aG docker $USER
# log out and back in so the group change applies

Step 2: create the project folder

mkdir -p ~/n8n && cd ~/n8n

Create a .env file for your secrets. Generate long random values (for example with openssl rand -hex 32) and keep a copy somewhere safe.

N8N_HOST=n8n.yourdomain.com
TZ=Asia/Kolkata
POSTGRES_PASSWORD=change-this-to-a-long-random-password
N8N_ENCRYPTION_KEY=change-this-to-a-long-random-string

Step 3: write docker-compose.yml

services:
  postgres:
    image: postgres:16
    restart: always
    environment:
      POSTGRES_USER: n8n
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: n8n
    volumes:
      - postgres_data:/var/lib/postgresql/data

  n8n:
    image: docker.n8n.io/n8nio/n8n
    restart: always
    ports:
      - "127.0.0.1:5678:5678"
    environment:
      DB_TYPE: postgresdb
      DB_POSTGRESDB_HOST: postgres
      DB_POSTGRESDB_PORT: 5432
      DB_POSTGRESDB_DATABASE: n8n
      DB_POSTGRESDB_USER: n8n
      DB_POSTGRESDB_PASSWORD: ${POSTGRES_PASSWORD}
      N8N_HOST: ${N8N_HOST}
      N8N_PORT: 5678
      N8N_PROTOCOL: https
      WEBHOOK_URL: https://${N8N_HOST}/
      GENERIC_TIMEZONE: ${TZ}
      N8N_ENCRYPTION_KEY: ${N8N_ENCRYPTION_KEY}
    volumes:
      - n8n_data:/home/node/.n8n
    depends_on:
      - postgres

volumes:
  postgres_data:
  n8n_data:

Two details matter here. n8n is bound to 127.0.0.1, so it is only reachable through the reverse proxy, not directly from the internet. And N8N_ENCRYPTION_KEY is set explicitly, so your saved credentials stay readable if you ever rebuild the container.

Step 4: start n8n

docker compose up -d
docker compose logs -f n8n

Step 5: add HTTPS with Caddy

Caddy obtains and renews certificates automatically. Install it from its official package repository, then put this in /etc/caddy/Caddyfile:

n8n.yourdomain.com {
    reverse_proxy 127.0.0.1:5678
}
sudo systemctl reload caddy

Open https://n8n.yourdomain.com and create the owner account. Nginx with Certbot works just as well if you prefer it.

Step 6: lock down the firewall

sudo ufw allow OpenSSH
sudo ufw allow 80,443/tcp
sudo ufw enable

Step 7: updating n8n

cd ~/n8n
docker compose pull
docker compose up -d

Take a backup first (see our n8n backup and restore guide) and read the release notes before jumping several versions.

Common mistakes

  • Wrong WEBHOOK_URL. If it is missing or points to localhost, production webhooks show the wrong URL and external services cannot reach them.
  • No Postgres. The default SQLite database works for testing, but Postgres is the safer choice for production.
  • Losing the encryption key. Without it, stored credentials cannot be decrypted after a rebuild.
  • Exposing port 5678 publicly. Keep it on localhost behind the proxy.
  • No backups or monitoring. A server that nobody watches fails quietly.

Want a dedicated n8n server with backups, monitoring and SSL already handled? Order in minutes and we provision it for you.

See Managed n8n Hosting Plans

Frequently asked questions

  • How much RAM does n8n need?
    2 GB is a sensible starting point for light to moderate workflows. Heavy workflows, large payloads or many concurrent executions need more.
  • Can I run n8n on a Windows RDP instead?
    It is possible with Docker Desktop, but a Linux VPS is lighter, cheaper and better supported for always-on n8n.
  • Do I need Postgres?
    Not for a quick test, but for production it is the recommended database and makes backups and scaling easier.