腾讯云之前和亚洲诚信TrustAsia合作,提供免费的一年SSL证书。最近亚洲诚信收紧,导致包括腾讯和阿里在内的公司,只免费提供三个月的SSL证书。同样是三个月免费SSL证书,那不如直接换成acme.sh,用ZeroSSL家的,还省得三个月手动改操作一次。

安装acme.sh

建议使用root账号,以下内容都是在Debian 12Nginx环境中进行的。
执行以下命令,其中my@example.com需要时真实有效的邮箱:

curl https://get.acme.sh | sh -s email=my@example.com

此时需要退出一次root账号,及激活shell中的acme.sh命令。执行exit或者直接关了ssh链接再重新登录都行。
执行以下命令,将acme.sh设置成本体自动更新:

acme.sh --upgrade --auto-upgrade

生成SSL证书

由于我使用了Nginx(其他的可以参考官方链接),所以直接使用--nginx标注了,其中ip.pa.ci是域名,如下所示:

acme.sh --issue -d ip.pa.ci --nginx

生成成功,将出现类似如下的提示:

Your cert is in: /root/.acme.sh/ip.pa.ci_ecc/ip.pa.ci.cer
Your cert key is in: /root/.acme.sh/ip.pa.ci_ecc/ip.pa.ci.key
The intermediate CA cert is in: /root/.acme.sh/ip.pa.ci_ecc/ca.cer
And the full chain certs is there: /root/.acme.sh/ip.pa.ci_ecc/fullchain.cer

安装SSL证书

需要将证书安装到指定位置(例如存放位置为/path/certificate/ip.pa.ci/),并且Nginx证书的格式和acme.sh的默认格式不一致,因此要额外操作,命令如下:

acme.sh --install-cert -d ip.pa.ci \
--key-file       /path/certificate/ip.pa.ci/ip.pa.ci.key  \
--fullchain-file /path/certificate/ip.pa.ci/ip.pa.ci_bundle.crt \
--reloadcmd     "systemctl force-reload nginx"

我为了方便记忆和管理,将SSL的私钥和公钥都重新命名了,如上的ip.pa.ci.keyip.pa.ci_bundle.crt。最后一行命令是用来重启Nginx的,以启用申请的证书。

检查定时任务

理论上,安装acme.sh的时候,就会自动写入一个crontab任务以自动更新证书,可以使用crontab -l命令查看是否存在。如下所示就是回自动更新SSL证书。

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

标签: ssl, acme.sh

添加新评论