← 返回
效率工具
中文
Caddy
Configure Caddy as a reverse proxy with automatic HTTPS and simple Caddyfile syntax.
将 Caddy 配置为反向代理,支持自动 HTTPS 和简洁的 Caddyfile 语法。
ivangdavila
效率工具
clawhub
v1.0.0 1 版本 99928.8 Key: 无需
#latest
概述
Caddy Configuration Rules
Automatic HTTPS
- Caddy provisions SSL certificates automatically — don't manually configure Let's Encrypt unless you have specific needs
- Domain must resolve to the server publicly for HTTP challenge — use DNS challenge for internal/wildcard certs
- Ports 80 and 443 must be free — Caddy needs both even for HTTPS-only (80 handles ACME challenges and redirects)
- Let's Encrypt has rate limits — use staging CA during testing to avoid hitting production limits
Caddyfile Syntax
- Indentation is significant — blocks are defined by indentation, not braces in shorthand
- Site blocks need a space before the opening brace:
example.com { not example.com{ - Use
caddy fmt --overwrite to fix formatting — catches most syntax issues - Validate before applying:
caddy validate --config /etc/caddy/Caddyfile
Reverse Proxy
- Caddy adds
X-Forwarded-For, X-Forwarded-Proto, X-Forwarded-Host automatically — don't add them manually - WebSocket works out of the box — no special configuration needed
- Load balancing is automatic with multiple backends — default is random, use
lb_policy to change - Passive health checks remove failed backends automatically
Docker Networking
- Use container names as hostnames:
reverse_proxy container_name:3000 - Caddy and backends must share a Docker network — default bridge doesn't support DNS resolution
- For Docker Compose, service names work as hostnames when on the same network
Configuration Management
- Use
caddy reload not restart — reload applies changes without dropping connections - Config changes are atomic — if new config fails validation, old config stays active
- Test without applying:
caddy adapt --config Caddyfile shows parsed JSON output
Certificate Storage
- Certificates stored in
~/.local/share/caddy by default — preserve this across reinstalls - For Docker, mount volumes for
/data and /config — losing these means re-requesting all certificates - Multiple Caddy instances need shared storage or will fight over certificates
Debugging
- Enable debug logging: add
debug as first line in global options block - Check certificate status in
/data/caddy/certificates/ directory - Common issue: DNS not pointing to server yet — certificates fail silently until domain resolves
Security Headers
- Caddy doesn't add security headers by default — add X-Frame-Options, X-Content-Type-Options explicitly
- HSTS is automatic when serving HTTPS — no manual configuration needed
Performance
- Handles thousands of concurrent connections without tuning
- HTTP/3 available with
servers { protocols h1 h2 h3 } - Compression automatic for text content
版本历史
共 1 个版本
-
v1.0.0
当前
2026-03-29 01:44 安全 安全
安全检测
腾讯云安全 (Sanbu)
安全,无风险
查看报告
🔗 相关推荐
productivity
steipete
获取当前天气和预报(无需API密钥)
★ 446
📥 226,503
productivity
ide-rea
使用百度AI搜索引擎(BDSE)进行网络搜索。适用于获取实时信息、文档资料或研究课题。
★ 239
📥 105,848
productivity
ivangdavila
创建、检查和编辑 Microsoft Word 文档及 DOCX 文件,支持样式、编号、修订记录、表格、分节符及兼容性检查等功能。
★ 440
📥 148,314