Self-Hosting Commento on a Hugo Blog
誰還不是個蝜蝂⋯⋯
你看,
順手背起來個評論系統,又。
Goal
Stand up a fully self‑hosted Commento++ instance for a Hugo site.
0 · Component Diagram
Layer | Choice / Notes |
---|---|
VPS | Any small VM ≈ 1 GB RAM |
OS | Ubuntu 24.04 LTS |
Database | PostgreSQL 16 |
Runtime | Docker (--network host ) |
Proxy + TLS | Caddy 2 (Let’s Encrypt auto‑renew) |
DNS / CDN | Cloudflare |
Static Site | Hugo + bearblog‑neo |
Comments | Commento++ (open‑source fork) |
Custom CSS | commento‑custom.css (hides footer) |
All examples use example.com
/ comments.example.com
. Replace them with your own.
1 · PostgreSQL 16 Setup
|
|
Create DB & user:
|
|
Put these at the top of /etc/postgresql/16/main/pg_hba.conf
:
host commento commento 127.0.0.1/32 md5
host commento commento ::1/128 md5
(Optional) make MD5 the default:
|
|
2 · Run Commento++ in Docker
|
|
3 · Caddy 2 Reverse Proxy + TLS
3.1 Install
|
|
3.2 /etc/caddy/Caddyfile
comments.example.com {
reverse_proxy localhost:8080
}
|
|
Keep Cloudflare record grey‑cloud (DNS‑only) until TLS is issued.
4 · Cloudflare DNS
Name | Type | Value | Proxy |
---|---|---|---|
comments | A | <VPS‑IP> |
DNS‑only |
Switch to Proxied after TLS works.
5 · First‑Time Commento Admin
- Visit
https://comments.example.com
→ Register - Add site:
Domain: example.com
Name: Example Blog
- Copy the generated
<script>
snippet.
6 · Hugo Integration
6.1 Partial
layouts/partials/commento.html
|
|
Insert in layouts/_default/single.html
:
{{ partial "commento.html" . }}
6.2 Hide “Powered by Commento”
static/css/commento-custom.css
|
|
Deploy your Hugo site.
7 · Maintenance
|
|
Caddy auto‑renews TLS; keep ports 80/443 open.
8 · Troubleshooting
Symptom | Fix |
---|---|
pq: unknown authentication response: 10 |
Ensure MD5 rules are first in pg_hba.conf , then ALTER ROLE commento WITH PASSWORD '...' ; or switch to SCRAM and Commento++ supports it. |
502 from Caddy | Check docker logs commento ; container may not be ready. |
Caddy won’t start | caddy validate , ensure ports 80/443 free. |
Footer still visible | Confirm /css/commento-custom.css loads via data-css-override . |
9 · Migration Checklist
- Backup DB + CSS + partials
- Re‑provision new VM (sections 1‑3)
- Restore DB with
psql
- Update DNS → Caddy re‑issues certs
Done. You now have a private, footer‑free Commento++ behind Cloudflare & Caddy, reproducible from this guide.
測試了幾個小時,不好玩,扔。