Files
nexus/wiki/concepts/HTTPS自动化证书.md
2026-04-22 19:20:32 +08:00

78 lines
2.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# HTTPS自动化证书
> HTTPS自动化证书Caddy 自动申请和管理 Let's Encrypt SSL 证书的机制,无需手动配置证书续期和文件路径。
## Overview
Caddy 是用 Go 语言编写的现代化 Web 服务器,其核心特性之一是**自动 HTTPS**——自动为配置中的域名申请 Let's Encrypt 免费证书,并在到期前自动续期。本方案中 Caddy 运行在 RackNerd VPS 上,为 *.ishenwei.online 的所有子域名提供统一的 HTTPS 访问。
## How It Works
### 申请流程
1. Caddy 监听 80 端口HTTP和 443 端口HTTPS
2. 收到域名请求后,自动向 Let's Encrypt 的 ACME 服务器发起证书申请
3. Let's Encrypt 通过 HTTP-01 或 TLS-ALPN-01 挑战验证域名所有权
4. 验证通过后,证书下载并存储在 Caddy 本地(`~/.caddy`
5. 证书到期前自动续期默认提前30天
### Caddyfile 配置示例
```
*.ishenwei.online {
tls {
dns cloudflare {env.CF_API_TOKEN}
}
reverse_proxy /* localhost:8080
}
```
## vs 传统 Nginx/Apache 方案
|| 特性 | Caddy | Nginx/Apache + Certbot |
|------|------|------|------------------------|
| 证书申请 | 自动 | 需手动 certbot |
| 证书续期 | 自动 | 需配置 cron + certbot renew |
| 证书路径 | 自动管理 | 需手动指定 |
| 配置文件 | 简洁 | 复杂 |
| 性能 | 轻量 | 成熟 |
## Architecture Context
本方案中 Caddy 接收来自公网的 HTTPS 请求后,根据域名将流量反向代理到对应的 FRP remotePort
```
[公网请求]
https://grafana.ishenwei.online
[RackNerd VPS: Caddy]
① 验证证书(自动)
② TLS 解密
③ 反向代理到 localhost:13000
[FRP Server]
隧道传输到内网节点
[Ubuntu Server 1: Grafana]
端口 3000
```
## Key Advantages
1. **零配置证书**:无需手动管理证书文件和续期脚本
2. **自动 HTTP→HTTPS 重定向**Caddy 默认将所有 HTTP 请求升级到 HTTPS
3. **Wildcard 证书**:通过 DNS-01 挑战支持 `*.ishenwei.online` 泛域名证书
4. **现代协议支持**:默认启用 HTTP/2 和 TLS 1.3
## Related Concepts
- [[反向代理]] — Caddy 的核心功能
- [[DNS托管]] — Cloudflare DNS 验证泛域名所有权
- [[内网穿透]] — FRP 隧道传输机制
- [[TLS 1.3]] — 最新 TLS 协议版本
- [[ACME]] — Let's Encrypt 证书自动颁发协议
## Related Entities
- [[Caddy]] — 自动 HTTPS 实现者
- [[RackNerd]] — Caddy 运行环境
- [[Cloudflare]] — DNS 服务提供商,支持 DNS-01 挑战
- [[frp]] — 内网服务的传输通道