acme.sh
acme.sh 是一个完全使用 shell 脚本编写的 ACME 客户端。它实现了完整的 ACME 协议,并支持例如 IPv6 和通配符证书。
安装
安装 acme.sh 软件包,如果您想使用独立模式,则还需要安装 socat。
用法
该软件包没有提供 man 手册页,但在 wiki 中提供了用法说明。执行 acme.sh --help
会输出一长串命令和参数。
其中涉及三个基本步骤
- 请求签发证书。
- 安装已签发的证书,使其变得有用。
- 长期维护证书。
如下面的例子所示。
签发新证书
您可以使用 -d
选项指定任何域名。
提示: 您可能想要指定 LetsEncrypt 作为您的默认 CA,因为从 2021 年 8 月 1 日起,acme.sh 使用 ZeroSSL 作为其默认 CA。
acme.sh
脚本支持不同的模式。以下是要指定的模式和选项的示例:
- Webroot 模式
$ acme.sh --issue -d example.com -d www.example.com -d cp.example.com -d '*.example.com' -w /home/wwwroot/example.com
- 独立模式,如果没有 Web 服务器运行,则添加
--standalone
(需要安装 socat)
$ acme.sh --issue --standalone -d example.com -d www.example.com -d cp.example.com
- Nginx 模式
$ acme.sh --issue --nginx -d example.com -d www.example.com -d cp.example.com
- DNS 模式(有关更多信息,请参见官方 wiki)
$ acme.sh --issue -d example.com -d '*.example.com' --dns dns_he
该项目的 wiki 列出了更多示例。
将证书安装到 Apache/Nginx 等
Nginx
$ acme.sh --install-cert -d example.com --key-file '/path/to/keyfile/in/nginx/example.key' --fullchain-file '/path/to/fullchain/nginx/example.cer' --reloadcmd "systemctl force-reload nginx"
Apache
$ acme.sh --install-cert -d example.com --cert-file '/path/to/certfile/in/apache/example.cer' --key-file '/path/to/keyfile/in/apache/example.key' --fullchain-file '/path/to/fullchain/certfile/apache/example.fullchain.cer' --reloadcmd "systemctl force-reload nginx apache2"
维护证书
证书将每 60 天续订一次。要定期运行 acme.sh
,可以设置 systemd 计时器。