神代綺凛

使用 acme.sh 申请 Let's Encrypt 泛域名SSL证书详细教程
Let's Encrypt 泛域名SSL已经出来挺长一段时间了,昨天才有需要,因此尝试了一下部署。 一开始看的是 ...
扫描右侧二维码阅读全文
01
2018/04

使用 acme.sh 申请 Let's Encrypt 泛域名SSL证书详细教程

Let's Encrypt 泛域名SSL已经出来挺长一段时间了,昨天才有需要,因此尝试了一下部署。

一开始看的是 Leonn 的教程,但不是很详细,自己弄懂了流程之后决定写一篇详细一点的教程(使用 CloudXNS 的 API 添加记录进行验证)。

Head Pic: 「アビーかわいい!!」/「おみなえし」[pixiv]
阿比我老婆!

acme.sh

acme.sh是一个实现了 acme 协议的脚本,可以从 Let's Encrypt 生成免费的SSL证书

本文只给出配合解析商 API 申请泛域名证书的过程教程,acme.sh还有很多很强大的功能例如配合 Nginx 或者 Apache 等自动申请证书,请自行查看 github 项目 wiki 发掘

https://github.com/Neilpang/acme.sh/wiki/%E8%AF%B4%E6%98%8E

1. 部署 acme.sh

curl https://get.acme.sh | sh
# 或者
wget -O- https://get.acme.sh | sh

安装过程不会污染已有的系统任何功能和文件,acme.sh会被自动安装到~/.acme.sh/

2. 获取 CloudXNS 的 API 信息

acme.sh目前支持 cloudflare, dnspod, cloudxns, godaddy 以及 ovh 等数十种解析商的 API,可以自动添加 TXT 记录来验证,不需要人工操作,十分便捷

详细可以看
https://github.com/Neilpang/acme.sh/blob/master/dnsapi/README.md

这里以 CloudXNS 为例,首先登录 CloudXNS,点击右上角帐户名-API管理,创建 API 之后你会得到 API KEY 和 SECRET KEY,记下他们,并且在“设置API白名单”中加上你服务器的 IP(其实不加也行,但是如果你在申请的时候出了 API 访问错误就尝试着加一下)

3. 开始申请证书

首先设置临时环境变量,配置我们刚才得到的 API 信息

# CloudXNS
export CX_Key="你的 API KEY"
export CX_Secret="你的 SECRET KEY"

其他解析商的环境变量名是不一样的,详情去这里看
https://github.com/Neilpang/acme.sh/blob/master/dnsapi/README.md

这个临时环境变量只需配置这一次,当成功申请证书后,API 信息会被自动保存在~/.acme.sh/account.conf,下次你使用acme.sh的时候会被自动使用

接下来正式开始申请泛域名证书,将example.com换成你自己的域名

~/.acme.sh/acme.sh --issue --dns dns_cx -d example.com -d '*.example.com'

--dns dns_cx参数表示使用 CloudXNS 的 API,如果是其他解析商,同样的,从上面那个链接可以看到对应参数

然后静静等待即可

4. 得到证书

申请完成后屏显会输出证书路径

证书是fullchain.cer
密匙是example.com.key

由于证书默认(在你没安装宝塔等同样调用 acme 签发证书的面板时)会在 acme 的内部目录~/.acme.sh/中生成,不建议直接使用该路径填写至 nginx 等配置中,而是使用--installcert命令,具体请参考↓

https://github.com/Neilpang/acme.sh/wiki/%E8%AF%B4%E6%98%8E#3-copy%E5%AE%89%E8%A3%85-%E8%AF%81%E4%B9%A6

关于证书续期

Let's Encrypt 证书的有效期为三个月,acme.sh会每隔60天自动帮你续期,无需你进行任何干预

如果你想强制续期或者取消自动续期可以看
https://github.com/Neilpang/acme.sh#11-how-to-renew-the-certs

搬瓦工VPS优惠套餐,建站稳如狗,支持支付宝,循环出账94折优惠码BWH3HYATVBJW
年付$47CN2线路,1核/1G内存/20G硬盘/1T@1Gbps【点击购买
季付$47CN2 GIA线路,1核/1G内存/20G硬盘/1T@2.5Gbps【点击购买
Last modification:May 5th, 2019 at 03:10 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment Cancel reply

21 comments

  1. 刹那  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 75.0.3770.142(Google Chrome 75.0.3770.142)
    dalao!CloudXNS停止免费服务了!以下公告:
    “关于 CloudXNS 停止免费用户的公告
    CloudXNS运营团队 2019-07-09

    为贯彻国家网络安全政策法规,加强监管力度,更好的服务于 VIP 客户,我司将于2019年7月16日0时起,停止免费使用我司 CloudXNS 客户的服务,有意向使用 VIP 服务的用户,请尽快与我司联系!

    1. 神代綺凜  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 75.0.3770.142(Google Chrome 75.0.3770.142)
      @刹那 嗯,可以换其他 DNS 解析服务商
  2. 灵虚  Mac OS X 10.14.4(Mac OS X 10.14.4) / Google Chrome 74.0.3729.131(Google Chrome 74.0.3729.131)
    该评论仅登录用户及评论双方可见
    1. 神代綺凜  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 74.0.3729.131(Google Chrome 74.0.3729.131)
  3. 余言  Android 9(Android 9) / Google Chrome 71.0.3578.99(Google Chrome 71.0.3578.99)
    大佬,问下,挂了cdn之后可以自动续签吗?
    1. 神代綺凜  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 71.0.3578.98(Google Chrome 71.0.3578.98)
      @余言 可以,用 DNS 方式验证和网站没有关系
      1. 余言  Android 9(Android 9) / Google Chrome 71.0.3578.99(Google Chrome 71.0.3578.99)
        @神代綺凜 大佬帮我看看好嘛,什么情况
        图片地址
        https://www.o104.cn/error.png
        1. 神代綺凜  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 71.0.3578.98(Google Chrome 71.0.3578.98)
          @余言 example.com是示例啊 换成你自己的域名
          1. 余言  Android 9(Android 9) / Google Chrome 71.0.3578.99(Google Chrome 71.0.3578.99)
            @神代綺凜 噗哈哈,我只注意到第二个域名倒是没注意前面还有一个,笑死个人,谢谢大佬哦
            1. 神代綺凜  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 71.0.3578.98(Google Chrome 71.0.3578.98)
              @余言 23333
              1. 余言  Android 9(Android 9) / Google Chrome 71.0.3578.99(Google Chrome 71.0.3578.99)
                @神代綺凜 还是不对
                https://www.o104.cn/error2.png
                并且我的acme在root文件夹
                1. 神代綺凜  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 71.0.3578.98(Google Chrome 71.0.3578.98)
                  @余言 已经写得很明确了,让你去那个网址看错误代码 35
                  1. 余言  Android 9(Android 9) / Google Chrome 71.0.3578.99(Google Chrome 71.0.3578.99)
                    @神代綺凜 emmm,明白错误原因的,已经成功,升级了一下acme
  4. kizimi  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 67.0.3396.99(Google Chrome 67.0.3396.99)
    现在的版本是不需要移动证书文件,直接在/.acme.sh/example.com下就可以使用了吗?
    1. 神代綺凜  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 67.0.3396.87(Google Chrome 67.0.3396.87)
      @kizimi 本来就不需要移动
      否则你无法享受到自动续签的便利
  5. 有趣的心  Windows 7 x64 Edition(Windows 7 x64 Edition) / Google Chrome 63.0.3239.132(Google Chrome 63.0.3239.132)
    哇塞,这个二维码怎么制作的好像要一个!
    1. 神代綺凜  Mac OS X(Mac OS X) / Safari(Safari)
      @有趣的心 原来某个可以制作gif二维码的网站,后来那网站没了。。
  6. 张尧博客  Windows 7 x64 Edition(Windows 7 x64 Edition) / Google Chrome 65.0.3325.181(Google Chrome 65.0.3325.181)
    不错不错,过来探望一下~
  7. zhujiwiki  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 50.0.2661.102(Google Chrome 50.0.2661.102)
    这个可操作性强,实用
    1. 神代綺凜  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 65.0.3325.162(Google Chrome 65.0.3325.162)
      @zhujiwiki 惊现主机百科大佬
      1. LYM  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 77.0.3865.90(Google Chrome 77.0.3865.90)