Self‑Host n8n on a VPS with Docker, PostgreSQL, and Caddy
Description and use
Deploy n8n on a VPS with Docker, PostgreSQL, and Caddy: automatic HTTPS, encrypted credentials, and persistent storage.
Problem
Deploy a production‑ready n8n instance with a persistent database, automatic HTTPS, and secure credentials management.
Outcome
n8n is running securely behind Caddy with automatic Let's Encrypt certificates, persistent PostgreSQL storage, and encrypted credentials, ready for production use.
Workflow
- Create project directory and generate .env with POSTGRES_PASSWORD, N8N_ENCRYPTION_KEY, and N8N_HOST
- Write docker‑compose.yml defining postgres, n8n, and caddy services with appropriate environment variables and volumes
- Create Caddyfile with reverse_proxy to n8n:5678
- Run docker compose up -d and verify services with docker compose ps and logs
- Access https://
<domain>to create owner account and start building workflows - Apply hardening: backup .env, configure firewall to allow only SSH, 80, 443, and set restart policy
Evidence
Use PostgreSQL, not the default SQLite: set DB_TYPE=postgresdb and the DB_POSTGRESDB_* variables.
Let Caddy own HTTPS: point your domain at the server and it provisions a Let's Encrypt certificate automatically.
- Record date: 2026-09-02T14:26:15.974Z