跳到主要内容

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 使用的卷。要配置 Certbot,请在此目录中添加 cli.ini 文件:

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

2) 配置值

下面以 ZeroSSL 的 ACME server 为例,说明让 Certbot 正确使用它所需的步骤。

首先(至少对于 ZeroSSL,你需要获取 EAB 凭据,地址在这里),我们添加电子邮件地址,并告知 Certbot 接受该服务的 TOS:

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

然后添加 server(以及需要时的 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"