Self‑Host n8n on a VPS with Docker, PostgreSQL, and Caddy
说明与用途
在 VPS 上使用 Docker、PostgreSQL 和 Caddy 部署 n8n:自动 HTTPS、加密凭证和持久化存储。
问题
Deploy a production‑ready n8n instance with a persistent database, automatic HTTPS, and secure credentials management.
结果
n8n is running securely behind Caddy with automatic Let's Encrypt certificates, persistent PostgreSQL storage, and encrypted credentials, ready for production use.
工作流
- 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
证据
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.
- 记录日期: 2026-09-02T14:26:15.974Z