Skip to content
返回云服务

用 Certbot 申请 Let's Encrypt:免费自动续期 TLS

用 Certbot 为 Nginx、Apache 或独立模式申请并自动续期 Let's Encrypt 免费 TLS 证书。

服务器安全入门

为什么

付费 TLS 证书 $50-200/年且需手动续期。Let's Encrypt 免费、自动(90 天证书 60 天续)、所有浏览器信任——2026 年无理由付费。

Verizon 2024 DBIR 显示 68% 的泄露涉及非恶意人为因素。SSH 密钥泄露和 S3 桶配置错误是主要攻击向量 — 加固将泄露风险降低 80% 以上。

何时使用

任何公共 HTTPS 站点用。内部/通配符用 DNS-01 验证。负载均衡器用 certbot --deploy-hook 推送证书。

如何做

1. Assess your workload requirements — compute, memory, storage, latency 2. Compare providers on price, region availability, and managed services 3. 安装:`apt install certbot python3-certbot-nginx`。Nginx:`certbot --nginx -d example.com -d www.example.com`(自动改配置)。独立(无 Web 服务器):`certbot certonly --standalone -d example.com`(停 80 端口服务)。DNS-01 通配符:`certbot certonly --dns-cloudflare --dns-cloudflare-credentials ~/.secrets/cf.ini -d '*.example.com'`。自动续期由 systemd timer 设置;测试 `certbot renew --dry-run`。证书在 /etc/letsencrypt/live/example.com/{fullchain.pem,privkey.pem}。 4. Set up IaC (Terraform/Pulumi) to provision resources 5. Configure monitoring, alerts, and cost budgets before going live

示例

# Nginx: 自动签发并配置 certbot --nginx -d example.com -d www.example.com \ --redirect --hsts --staple-ocsp \ --email [email protected] --agree-tos --no-eff-email # 通过 Cloudflare DNS 通配符 cat > ~/.secrets/cf.ini <<'EOF' dns_cloudflare_api_token = 你的_CF_TOKEN EOF chmod 600 ~/.secrets/cf.ini certbot certonly --dns-cloudflare \ --dns-cloudflare-credentials ~/.secrets/cf.ini \ -d '*.example.com' -d example.com # 测试自动续期 certbot renew --dry-run systemctl status certbot.timer

常见问题

  • ⚠速率限制:每域每周 5 重复证书——别循环重签;复用现有。
  • ⚠DNS-01 需 API token 仅 Zone:DNS:Edit 权限,非全账户——最小权限。
  • ⚠80 端口被占时独立验证失败——先停 Nginx 或用 --webroot。

最佳实践

  • ✓用 --deploy-hook 续期后重载 Nginx/HAProxy,无需重启即用新证书。
  • ✓通配符或内部域用 DNS-01(无需 80 端口,防火墙后可用)。
  • ✓监控 certbot.timer,续期失败告警——静默续期失败导致证书过期宕机。

常见问题解答

什么是用 Certbot 申请 Let's Encrypt:免费自动续期 TLS?它解决什么问题?

用 Certbot 为 Nginx、Apache 或独立模式申请并自动续期 Let's Encrypt 免费 TLS 证书。 它可帮助开发者在不自建基础设施的前提下完成部署、存储与扩展,是云服务选型的核心参考。

如何在 5 分钟内上手用 Certbot 申请 Let's Encrypt:免费自动续期 TLS?

两步即可跑通:① Assess your workload requirements — compute, memory, storage, latency;② Compare providers on price, region availability, and managed services。建议先用免费套餐验证流程,再接入生产环境。

用 Certbot 申请 Let's Encrypt:免费自动续期 TLS 最容易踩的坑是什么?

最高频的问题是:速率限制:每域每周 5 重复证书——别循环重签;复用现有。。建议在上线前用 checklist 逐项核对,并在 CI 中加入策略与配置扫描。

用 Certbot 申请 Let's Encrypt:免费自动续期 TLS 的最佳实践有哪些?

用 Certbot 申请 Let's Encrypt:免费自动续期 TLS 的最佳实践包括:用 --deploy-hook 续期后重载 Nginx/HAProxy,无需重启即用新证书。;通配符或内部域用 DNS-01(无需 80 端口,防火墙后可用)。;监控 certbot.timer,续期失败告警——静默续期失败导致证书过期宕机。。其中首条「用 --deploy-hook 续期后重载 Nginx/HAProxy,无需重启即用新证书。」应作为团队默认规范写入 IaC 模板。

用 Certbot 申请 Let's Encrypt:免费自动续期 TLS 如何控制成本与避免账单意外?

三招防超支:① 为所有资源打 env/team 标签并启用账单告警;② 用预算阈值触发 Slack/邮件通知;③ 定期用 Cost Explorer 审查闲置资源并清理。用 Certbot 申请 Let's Encrypt:免费自动续期 TLS 多数提供免费套餐,先在免费额度内验证再放量。