Sheet & Flow
Launch offer: 20% off every product and bundle with code LAUNCH20 until October 14, 2026. Browse the store

Self-Host n8n with Docker Compose, PostgreSQL and Automatic HTTPS (2026 Guide)

Short on time? The n8n Production Self-Hosting Kit ($29) is the finished, tested version of what this tutorial builds.

Running n8n yourself is cheap and gives you full control. The default "quick start" (SQLite, no HTTPS, latest tag) is fine for a test, but not for workflows your business depends on.

This is the setup we tested end to end with n8n 2.40.6.

What you need

  • A Linux server with 2 GB of RAM. Most €5–10/month VPS plans are enough for a small team.
  • Docker with the Compose plugin. Check with docker compose version.
  • A subdomain such as n8n.example.com with an A record pointing at the server.
  • Ports 80 and 443 open. Caddy needs both to get the certificate.

(Prefer not to run a server? n8n Cloud is the hosted option.)

The three files

Generate them with the free n8n Docker Compose generator. It creates the database password and encryption key in your browser. Or write them by hand:

  • docker-compose.yml has three services:
  • postgres:17-alpine with a health check
  • docker.n8n.io/n8nio/n8n:<exact version>, which waits for Postgres to be healthy
  • caddy:2-alpine, which publishes 80/443 and proxies to n8n:5678
  • .env holds the domain, email, timezone, version, database password and N8N_ENCRYPTION_KEY.
  • Caddyfile is a few lines: your email, your domain and reverse_proxy n8n:5678. Caddy obtains and renews the Let's Encrypt certificate automatically.

Then:

chmod 600 .env
mkdir -p local-files
docker compose up -d
docker compose ps        # wait until n8n shows (healthy)

Open https://n8n.example.com and create the owner account.

The n8n 2.x settings that matter

We found these while testing on 2.40.6:

  1. Use PostgreSQL 17 or newer. With Postgres 16, n8n 2.40 logs "Postgres 16 is outside the supported range and receives compatibility support only."
  2. The Read/Write Files node is sandboxed. n8n 2.x only allows folders listed in N8N_RESTRICT_FILE_ACCESS_TO. Set it to /files, mount ./local-files:/files, and create subfolders before writing to them. Otherwise you get "Access to the file is not allowed".
  3. Set the URL variables behind a proxy. Set N8N_HOST, N8N_PROTOCOL=https, WEBHOOK_URL=https://your-domain/ and N8N_PROXY_HOPS=1. Without them, webhook URLs show localhost:5678.

Also worth setting:

  • EXECUTIONS_DATA_PRUNE=true with a max age, so the database doesn't grow forever
  • GENERIC_TIMEZONE, so Schedule triggers fire at the times you expect

Pin the version

Use an exact tag like 2.40.6, never latest. To upgrade:

  1. Read the release notes.
  2. Take a backup.
  3. Change the version in .env.
  4. Run docker compose pull n8n && docker compose up -d n8n.

Don't downgrade without restoring the pre-upgrade backup, because newer versions may migrate the database.

Save the encryption key now

Every credential you store in n8n is encrypted with N8N_ENCRYPTION_KEY. A database backup without the key cannot decrypt a single credential. Put the key in your password manager today. The next tutorial covers how to back up n8n properly.

Done-for-you version

The n8n Production Self-Hosting Kit is this setup plus a set of tested scripts:

  • setup.sh, which generates secrets and never overwrites an existing key
  • encrypted backup.sh
  • restore.sh, which refuses a mismatched key
  • a restore drill that proves your credentials decrypt
  • a safe upgrade.sh
  • a health check

We tested it by wiping every volume and restoring.

Not affiliated with n8n GmbH.

Free tool: n8n Docker Compose Generator (Postgres + HTTPS)

Written with AI assistance. Every formula, command and number on this page was tested before publishing (see each section). Product links go to our store.