ACME 客户端与自动化

Let's Encrypt 证书配置文件(profile)选择与配置

作者: · 最后核实

Let's Encrypt 的证书配置文件(profile)有三种:默认的 classic、45 天的 tlsserver 和 160 小时的 shortlived。在 ACME 客户端里写上配置文件名就能切换,续期时间要跟着有效期调整。

配置文件选择基于 IETF 的 ACME profiles 草案,支持的客户端版本:Certbot 4.0+、acme.sh 3.1.2+、lego v5、Caddy 2(实验性选项)、Traefik v3、cert-manager 1.18+、Nginx ACME 模块 0.3.0+。

前提条件

配置文件决定证书多短命,所以续期必须已经全自动。

  • ACME 客户端版本不低于上面列出的版本。
  • 续期任务至少每天运行一次;用 shortlived 时每天两次更稳妥。
  • 业务系统不依赖证书主题里的 Common Name(对 tlsserver 和 shortlived 而言)。

第一步:对比三种配置文件

三种配置文件的区别在有效期、名称数量和是否包含 Common Name,不指定时用 classic。

配置文件 有效期 名称数量 Common Name 说明
classic 90 天;2027-02-10 起 64 天;2028-02-16 起 45 天 最多 100 个 DNS 名称 包含 不指定时的默认值
tlsserver 45 天 最多 25 个 DNS 名称 不含 域名验证结果只复用 7 小时
shortlived 160 小时 最多 25 个 DNS 名称或 IP 不含 不需要吊销信息

原来的 tlsclient 配置文件已于 2026 年 7 月 8 日下线,classic 从 2026 年 2 月 11 日起不再包含 TLS 客户端认证 EKU。客户端证书请改用私有 CA。

第二步:查看服务器提供的配置文件

ACME 目录的 profiles 字段列出服务器当前提供的配置文件:

curl -s https://acme-v02.api.letsencrypt.org/directory | python3 -m json.tool | grep -A6 '"profiles"'

测试环境目录 https://acme-staging-v02.api.letsencrypt.org/directory 提供同样的配置文件,可以先在那里测试。

第三步:在客户端里配置

每个客户端都用一个参数或配置项指定配置文件名,示例统一用 tlsserver。

Certbot 4.0+(4.1 起会把选择保存到续期配置):

sudo certbot certonly --nginx -d example.com --preferred-profile tlsserver

用 --required-profile 时,服务器不提供该配置文件就直接报错,而不是退回默认值。

acme.sh 3.1.2+:

acme.sh --issue --server letsencrypt -d example.com --dns dns_ali --cert-profile tlsserver

lego v5:

lego run --accept-tos --path /etc/lego --dns alidns -d example.com --profile tlsserver

Caddy(官方标为实验性):

example.com {
    tls {
        issuer acme {
            profile tlsserver
        }
    }
}

Traefik v3 静态配置(同时把 certificatesDuration 设为有效期小时数,续期时间才对得上):

certificatesResolvers:
  le:
    acme:
      email: admin@example.com
      storage: /letsencrypt/acme.json
      profile: tlsserver
      certificatesDuration: 1080
      httpChallenge:
        entryPoint: web

cert-manager 1.18+(Issuer 或 ClusterIssuer 的 spec.acme.profile):

spec:
  acme:
    server: https://acme-v02.api.letsencrypt.org/directory
    profile: tlsserver

Nginx ACME 模块 0.3.0+,写在 acme_issuer 块里:

profile tlsserver;

验证

切换到 tlsserver 后,新证书的有效期是 45 天,主题为空(没有 CN)。下次签发后,用 SSL 证书检查 或终端确认:

curl ssl.sh/example.com
openssl s_client -connect example.com:443 -servername example.com </dev/null 2>/dev/null \
  | openssl x509 -noout -subject -dates

有效期计算器 可以算出应该何时续期。

自动续期

配置文件越短,续期调度越关键。Certbot 4.0+ 在剩余三分之一有效期时续期(有效期不足 10 天时为一半),4.1+ 按 ARI 续期;acme.sh 3.1.4+ 和 lego v5 默认按 ARI;Caddy 也支持 ARI。删掉写死的“到期前 30 天续期”设置:对 45 天证书几乎每次都会续期,对 6 天证书则做不到。acme.sh 3.1.5 起显式的 --days 会覆盖 ARI,没有必要就不要设置。把域名加到 ssl.sh 监控(开发中),续期卡住时几天内就能发现。

常见问题排查

  • account is not permitted to use certificate profile:这个配置文件没有对你的账户或环境开放,查看目录列表和 Let's Encrypt 公告。
  • unrecognized arguments: --preferred-profile 之类:客户端版本太旧,不支持配置文件,升级即可。
  • 6 天证书显示下次续期在 60 天后:客户端按 90 天有效期估算,依靠 ARI 或显式设置续期时间,并用监控确认。
  • 老系统提示证书主题为空:它在读 CN,修改程序,或在 2027 年 2 月前继续用 classic。
  • 客户端证书认证失效:见 客户端认证 EKU 被移除。
  • 测试时订单太多被限制:改用测试环境,见 Let's Encrypt 频率限制。

常见问题

现在就该切到 tlsserver 吗?

续期已经完全自动、每天至少检查一次的,现在切换可以提前暴露问题,不必等到 2027 年 2 月默认变 64 天、2028 年 2 月变 45 天时才发现。还有任何手动环节的,先把手动环节消灭掉;有效期越短,手动环节越早出事。

证书没有 Common Name 会影响什么?

浏览器和现代 TLS 库只校验 SAN(使用者可选名称),公网访问不受影响。读取证书 CN 来识别证书的老设备、监控脚本或自研代码,在使用 tlsserver、shortlived 前需要先改。

6 天的 shortlived 适合什么场景?

希望少依赖吊销(私钥泄露后几天内证书就失效),或者需要 IP 地址证书(Let's Encrypt 只在 shortlived 下签发 IP 证书)。它需要每隔几天续期一次,只适合按 ARI 或按一半有效期续期的客户端。

怎么查看 CA 提供哪些配置文件?

看 ACME 目录里的 profiles 字段:curl -s https://acme-v02.api.letsencrypt.org/directory。Let's Encrypt 说明目录里的列表是权威来源;acme.sh 也可以用 --list-profiles 查看。

资料来源

  1. Let's Encrypt: Profiles
  2. Let's Encrypt: Decreasing Certificate Lifetimes to 45 Days
  3. Let's Encrypt: Ending TLS Client Authentication Certificate Support
  4. Certbot User Guide
  5. acme.sh wiki: Profile selection
  6. lego: Commands & Flags
  7. Caddy: tls directive
  8. cert-manager: ACME
  9. nginx: Module ngx_http_acme_module