使用acme.sh申请泛域名证书

hqs Posted on 2022-08-12 2200 Views


这里使用了接入Cloudflare的域名作为演示,目前最新版的acme.sh默认使用ZeroSSL申请证书

acme的GitHub地址:https://github.com/acmesh-official/acme.sh

全程大概需要耗时15分钟这个样子

1. 安装 acme.sh(直接选自官方wiki

安装很简单, 一个命令:

curl  https://get.acme.sh | sh -s [email protected]

普通用户和 root 用户都可以安装使用. 安装过程进行了以下几步:

  1. 把 acme.sh 安装到你的 home 目录下:
~/.acme.sh/

并创建 一个 bash 的 alias, 方便你的使用: alias acme.sh=~/.acme.sh/acme.sh

更高级的安装选项请参考: https://github.com/Neilpang/acme.sh/wiki/How-to-install

安装过程不会污染已有的系统任何功能和文件, 所有的修改都限制在安装目录中: ~/.acme.sh/

2.配置acme.sh

有需要的可以先开启自动更新

acme.sh --upgrade --auto-upgrade
(推荐先把cron装上)

获取Cloudflare Global API

登录Cloudflare并点击右上角的个人资料

看不懂英文请自行翻译

左侧找到API Tokens,再点击查看Global API即可获取

复制API并替代掉引号内的内容,然后再底下输入CF的邮箱即可

export CF_Key="Enter your Global API Token"
export CF_Email="Enter your email [email protected]"

如果不是用的Cloudflare也可以从这里找到使用方法

https://github.com/acmesh-official/acme.sh/wiki/dnsapi

注册ZeroSSL账户

目前ZeroSSL泛域名申请只支持通过命令申请,网站无法直接获得

可以选择注册ZeroSSL账户,已经注册了的会自动关联acme.sh。当然,没有这一步也会自动注册一个账户。

acme.sh --register-account -m [email protected] --server zerossl

3.申请证书

直接一梭哈把域名换成你的就行了

acme.sh --issue -d example.com -d '*.example.com' --dns dns_cf

或者这样

acme.sh --issue -d *.example.com -d example.com --dns dns_cf

过程会消耗几分钟,一般情况下等着就行了

成功后应该会有这样的提示,告诉了你证书的路径(推荐用fullchain.cer的这个避免兼容性问题)

4.更新证书

用以下命令可以强制更新证书,不用等到60天后自动更新

acme.sh --renew -d example.com --force

等待补充

This author has not provided a description.
Last updated on 2022-08-12