How to Self-Host n8n with Docker Compose on Ubuntu 24.04
说明与用途
在 Ubuntu 24.04 VPS 上使用 Docker Compose、PostgreSQL、Caddy 和外部任务运行器部署 n8n,提供 HTTPS 和安全凭据存储。
问题
Deploy a secure, production‑ready n8n instance on a VPS with HTTPS, PostgreSQL, and an external task runner.
结果
n8n is now running securely behind Caddy with HTTPS, using PostgreSQL for persistence and an external task runner for code execution, all managed via Docker Compose.
工作流
- Open firewall for SSH, 80, 443
- Create project directory and .env with secrets
- Add init-data.sh to create non‑root PostgreSQL user
- Write compose.yaml defining postgres, n8n, and runners services
- Run docker compose up -d
- Verify Caddy obtains TLS certificate and routes to n8n
- Confirm n8n accessible via https://YOUR_DOMAIN
- Update by editing .env and re‑deploying
证据
This n8n Docker Compose stack runs n8n 2.41.6, its n8nio/runners task runner and PostgreSQL 18, with Caddy in front for HTTPS on ports 80 and 443.
Publish n8n on 127.0.0.1:5678 only. Docker-published ports bypass UFW, so a public 5678 stays open even when UFW denies it.
Set N8N_ENCRYPTION_KEY, N8N_WEBHOOK_URL and N8N_PROXY_HOPS=1.
n8n's sizing example lists 320 MB to 2 GB of memory for n8n itself. The optional n8n Assistant sandbox needs 4 GB RAM and 2 vCPU.
- 记录日期: 2026-10-15T14:56:03.891Z