0%

关于acme.sh的摘录2

4. 安装证书

前面证书生成以后, 接下来需要把证书 copy 到真正需要用它的地方.

默认生成的证书都放在安装目录下: ~/.acme.sh/, 请不要直接使用此目录下的文件。 不要直接让 nginx/apache 的配置文件使用这下面的文件,这里面的文件都是内部使用, 而且目录结构可能会变化。

正确的使用方法是使用--install-cert命令,并指定目标位置, 然后证书文件会被copy到相应的位置。

4.1 Apache example

1
2
3
4
5
acme.sh --install-cert -d example.com \
--cert-file /path/to/certfile/in/apache/cert.pem \
--key-file /path/to/keyfile/in/apache/key.pem \
--fullchain-file /path/to/fullchain/certfile/apache/fullchain.pem \
--reloadcmd "service apache2 force-reload"

4.2 Nginx example

1
2
3
4
acme.sh --install-cert -d example.com \
--key-file /path/to/keyfile/in/nginx/key.pem \
--fullchain-file /path/to/fullchain/nginx/cert.pem \
--reloadcmd "service nginx force-reload"

注意:这里用的是 service nginx force-reload, 不是 service nginx reload, 据测试, reload 并不会重新加载证书, 所以用的 force-reload。

Nginx 的配置 ssl_certificate 使用 /etc/nginx/ssl/fullchain.cer ,而非 /etc/nginx/ssl/.cer ,否则 SSL Labs 的测试会报 Chain issues Incomplete 错误。

–install-cert命令可以携带很多参数, 来指定目标文件. 并且可以指定 reloadcmd, 当证书更新以后, reloadcmd会被自动调用,让服务器生效。

值得注意的是, 这里指定的所有参数都会被自动记录下来, 并在将来证书自动更新以后, 被再次自动调用。

5. 查看已安装证书信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
acme.sh --info -d example.com
# 会输出如下内容:
DOMAIN_CONF=/root/.acme.sh/example.com/example.com.conf
Le_Domain=example.com
Le_Alt=no
Le_Webroot=dns_ali
Le_PreHook=
Le_PostHook=
Le_RenewHook=
Le_API=https://acme-v02.api.letsencrypt.org/directory
Le_Keylength=
Le_OrderFinalize=https://acme-v02.api.letsencrypt.org/acme/finalize/23xxxx150/781xxxx4310
Le_LinkOrder=https://acme-v02.api.letsencrypt.org/acme/order/233xxx150/781xxxx4310
Le_LinkCert=https://acme-v02.api.letsencrypt.org/acme/cert/04cbd28xxxxxx349ecaea8d07
Le_CertCreateTime=1649358725
Le_CertCreateTimeStr=Thu Apr 7 19:12:05 UTC 2022
Le_NextRenewTimeStr=Mon Jun 6 19:12:05 UTC 2022
Le_NextRenewTime=1654456325
Le_RealCertPath=
Le_RealCACertPath=
Le_RealKeyPath=/etc/acme/example.com/privkey.pem
Le_ReloadCmd=service nginx force-reload
Le_RealFullChainPath=/etc/acme/example.com/chain.pem

6. 更新证书

目前证书在 60 天以后会自动更新, 你无需任何操作。今后有可能会缩短这个时间, 不过都是自动的, 你不用关心。

请确保 cronjob 正确安装, 看起来是类似这样的:

1
2
3
crontab  -l

56 * * * * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null

7. 更新 acme.sh

目前由于 acme 协议和 letsencrypt CA 都在频繁的更新, 因此 acme.sh 也经常更新以保持同步。

升级 acme.sh 到最新版 :

1
acme.sh --upgrade

如果你不想手动升级, 可以开启自动升级:

1
acme.sh --upgrade --auto-upgrade

之后, acme.sh 就会自动保持更新了.

你也可以随时关闭自动更新:

1
acme.sh --upgrade --auto-upgrade  0

8. 签发ECC证书

只需设置 keylength带前缀的参数 ec-.

例如:
单域ECC证书

1
acme.sh --issue -w /home/wwwroot/example.com -d example.com --keylength ec-256

SAN多域ECC证书

1
acme.sh --issue -w /home/wwwroot/example.com -d example.com -d www.example.com --keylength ec-256

签发ECC证书时keylength的参数如下所示;
有效值为:
ec-256(prime256v1,“ECDSA P-256”,这是默认密钥类型)
ec-384(secp384r1,“ECDSA P-384”)
ec-521(secp521r1,“ECDSA P-521”,Let’s Encrypt 尚不支持。)
2048 (RSA2048)
3072 (RSA3072)
4096 (RSA4096)