Tutorials / n8n

Deploy n8n with PostgreSQL and HTTPS

intermediate50 minLast reviewed: 2026-07-15Target OS: Ubuntu 24.04 LTS

Written by uNode Engineering; reviewed by uNode Operations.

Persistent database, encryption-key retention, public URL, reverse-proxy boundary, logging, and restore-set requirements reviewed.

n8n stores credentials encrypted with its encryption key. Losing that key or the database makes workflows difficult or impossible to recover, so treat both as backup-critical secrets.

Illustration for How to Deploy n8n with Docker Compose

Prerequisites

  • Ubuntu 24.04 with Docker Engine and Compose.
  • A DNS name pointing at the VPS.
  • Strong random database and n8n encryption secrets.
Open console server deploy

Step 1

Create a private environment file

Generate unique secrets, restrict the file, and never commit it.

install -d -m 700 /opt/n8n
cd /opt/n8n
umask 077
openssl rand -hex 32

Step 2

Define PostgreSQL and n8n

Use persistent named volumes, a private Compose network, health checks, and current pinned image versions. Expose n8n only through the reverse proxy.

Step 3

Set the public URL

Configure N8N_HOST, N8N_PROTOCOL=https, WEBHOOK_URL, and N8N_EDITOR_BASE_URL for the final hostname before creating production webhooks.

Step 4

Start and verify

Start the stack, inspect health and logs, then create the first owner through HTTPS.

docker compose up -d
docker compose ps
docker compose logs --tail=100 n8n

Step 5

Back up a restore set

Back up PostgreSQL, the n8n data volume, Compose file, and encryption key off-host. Perform a restore drill before relying on the automation service.