申请免费的泛域名SSL证书
目录
警告
本文最后更新于 2024-06-10,文中内容可能已过时。
1 前言
摸鱼了一下午+一晚上,终于搞好了。 之前总是偷懒想用别人搭建好的docker镜像来弄,结果报错了一下午还没搞好。最后自己动手,丰衣足食。 学到的教训:不要偷懒,多看官方文档。
2 安装
以下教程主要基于工具acme.sh, 如果有不懂的地方请参考 官方文档 https://github.com/Neilpang/acme.sh/wiki/说明
以下教程基于此文章进行更进一步的说明。
- 安装
acme.sh。curl https://get.acme.sh | sh*普通用户和root用户都可以安装使用,安装脚本其实是进行了如下操作:
1)会把
acme.sh安装到你所执行命令用户的用户目录下: *~/.acme.sh/2)会创建*
bash的 *alias,方便你的使用:alias > acme.sh=~/.acme.sh/acme.sh3)会自动为你创建*
cronjob脚本,每天零点自动检测所有的证书,如果某证书快过期需要更新,则会自动更新该证书。 安装过程不会污染已有的系统任何功能和文件,所有后续的修改都将限制在安装目录中:~/.acme.sh/ - 验证域名并生成证书。
验证的方式有HTTP文件验证,DNS手动验证,DNS自动认证,更详细的说明请参考官方的dnsapi。
这里只介绍最简单最方便的DNS自动认证方式。
- 通过DNS服务器提供
key与secret实现自动验证。所以需要申请你域名解析商的key与secret。例如我是在华为云买的域名,放在阿里云上进行解析,所以我需要去申请阿里云的key与secret。倒入环境变量。 注意:我用的是阿里的,所以环境变量名为Ali_Key, 你如果使用其他家的环境变量明是不一样的,到官方的dnsapi中去查就行。export Ali_Key="LTAI4G44567890j5jnt1" export Ali_Secret="ZohryZoB5EuEq1234567ACiE" - 运行命令注册一下账号。(我也不知道是干什么,不然为报错
Please update your account with an email address first.)acme.sh --register-account -m acmshNB@qq.com - 正式申请证书。
注意:–dns后面跟的参数与你的域名解析商有关,其他商对应的名字到官方的dnsapi中去查就行。
运行成功后的输出如下所示
acme.sh --issue -d hifool.cn -d "*.hifool.cn" --dns dns_ali[Sat Jul 24 21:54:47 CST 2021] Your cert is in /home/rui/.acme.sh/hifool.cn/hifool.cn.cer [Sat Jul 24 21:54:47 CST 2021] Your cert key is in /home/rui/.acme.sh/hifool.cn/hifool.cn.key [Sat Jul 24 21:54:47 CST 2021] The intermediate CA cert is in /home/rui/.acme.sh/hifool.cn/ca.cer [Sat Jul 24 21:54:47 CST 2021] And the full chain certs is there: /home/rui/.acme.sh/hifool.cn/fullchain.cer - 移动证书
acme.sh --install-cert -d hifool.cn -d "*.hifool.cn" \ --key-file /home/rui/acmeNB/hifool.cn/privkey.pem \ --fullchain-file /home/rui/acmeNB/hifool.cn/fullchain.pem \ --reloadcmd "service nginx force-reload" - 配置证书。就不讲了。
- 通过DNS服务器提供
- 关于自动更新。官方文档中说
目前证书在 60 天以后会自动更新, 你无需任何操作.因为在我们第一步安装的时候设置了定时任务。至于是否能自动更新,我还不知道。$ crontab -l 42 0 * * * "/home/rui/.acme.sh"/acme.sh --cron --home "/home/rui/.acme.sh" > /dev/null
3 手动dns申请
参考https://wuuconix.link/2022/01/29/acme-sh/
acme.sh --issue --dns -d "*.realfakenews.cf" -d "realfakenews.cf" --yes-I-know-dns-manual-mode-enough-go-ahead-please
acme.sh --renew --dns -d "*.realfakenews.cf" -d "realfakenews.cf" --yes-I-know-dns-manual-mode-enough-go-ahead-please
acme.sh --install-cert -d "*.realfakenews.cf" -d "realfakenews.cf" \
--key-file /home/rui/acmeNB/realfakenews.cf/key.pem \
--fullchain-file /home/rui/acmeNB/realfakenews.cf/cert.pem \
--reloadcmd "service nginx force-reload"
4 使用freessl网站进行申请
https://zigu.me/index.php/2023/02/15/1/ 优点:只需要添加一个cname的解析记录,无需api,特别适合freenom免费域名的证书自动续期。