CapRover

Certbot 覆盖配置

注意:

绝大多数(几乎所有)用户都不需要修改 Certbot 配置。CapRover 会自动为你管理它。你应该跳过本页!


自定义 Certbot 命令以使用 DNS-01 challenge

从 CapRover 1.12.0 起,你可以自定义 Certbot 生成 SSL 证书时使用的命令。默认情况下,CapRover 使用以下命令:

certbot certonly --webroot -w ${webroot} -d ${domainName}

它通过 HTTP-01 challenge 工作。在该模式下,Certbot 会向 http://<YOUR_DOMAIN>/.well-known/acme-challenge/<TOKEN> 发送请求来验证域名所有权,其中 <TOKEN> 的内容由 Certbot 生成。

该 challenge 对大多数用户都适用,但如果你愿意,也可以改用其他 challenge。你可以通过覆盖 Certbot 的证书生成命令来实现。

1) Certbot Docker 镜像

默认的 Certbot Docker 镜像不包含第三方插件。你需要构建一个自定义镜像:

例如,对于 Cloudflare:

# Change this to any other base image listed here: https://hub.docker.com/r/certbot/certbot
## Make sure to use the same version that CapRover uses by default (`certbotImageName` in [CaptainConstant](https://github.com/caprover/caprover/blob/master/src/utils/CaptainConstants.ts#L58)) 
BASE_IMAGE="certbot/dns-cloudflare:v2.11.0"  

TEMP_DOCKERFILE=$(mktemp)
cat > $TEMP_DOCKERFILE <<EOF
FROM $BASE_IMAGE
ENTRYPOINT ["/bin/sh", "-c"]
CMD ["sleep 9999d"]
EOF
docker build -t certbot-customized -f $TEMP_DOCKERFILE .
rm $TEMP_DOCKERFILE

2) 保存你的 DNS 凭据

mkdir /captain/data/letencrypt/etc/captain-files
nano mycreds.ini

然后写入你的 DNS 凭据。例如,对于 Cloudflare DNS,你可以这样写:

# Cloudflare API token used by Certbot
dns_cloudflare_api_token = 0123456789abcdef0123456789abcdef01234567

更多细节见这里

3) 覆盖 Certbot 命令

通过运行以下命令编辑 /captain/data/config-override.json

nano /captain/data/config-override.json

然后填入以下内容。请确保替换 your/repo:certbot-sleeping,并根据你的需求调整 certbotCertCommand

例如,对于通配符证书,你需要同时为主域名和子域名申请证书,需要像这样添加:-d ${domainName} -d \"*.${domainName}\"

{
  "skipVerifyingDomains": "true",
  "certbotImageName": "certbot-customized",
  "certbotCertCommandRules": [
    {
      "domain": "*",
      "command":  "certbot certonly --dns-cloudflare --dns-cloudflare-credentials /etc/letsencrypt/captain-files/mycreds.ini -d ${domainName} -d \"*.${domainName}\"" 
    }
  ]
}

4) 重启 CapRover

docker service update captain-captain --force

现在,当你让 CapRover 生成 SSL 证书时,它将使用 DNS challenge。




配置 Certbot 使用新的 ACME Server

1) 创建配置文件

通常,目录 /captain/data/letsencrypt/etc 中会挂载 Certbot 使用的 volume。 要配置 Certbot,请在该目录下添加一个 cli.ini 文件:

$ cd /captain/data/letsencrypt/etc/
$ nano cli.ini

2) 配置参数

下面以 ZeroSSL 的 ACME 服务器为例,说明如何让 Certbot 正确与其配合工作。

首先(至少对于 ZeroSSL),你需要先获取 EAB 凭据。然后添加邮箱,并让 Certbot 接受该服务的服务条款:

email = foo@example.com
agree-tos = true

接着添加服务器地址(以及在需要时补充 EAB 凭据):

server = https://acme.zerossl.com/v2/DV90 # (change it with your ACME server)
eab-kid = some-short-string
eab-hmac-key = a-big-key

3) 重启 Certbot

要让改动生效,需要更新 Certbot 服务:

$ docker service update captain-certbot

完成!

4) CAA 记录

请记得在 DNS 中添加 CAA 记录,以避免在生成 SSL 证书时出现问题。

例如,ZeroSSL 需要你配置:

<your domain>. 3600 IN CAA 0 issue "sectigo.com"
<your domain>. 3600 IN CAA 0 issuewild "sectigo.com"