Let's encrypt 通配域名(二级, 三级)

概述

Let's encrypt 申请通配域名的方式以下:web

certbot certonly --manual \
-d '*.exampple.com' \
--agree-tos \
--email domain@example.com \
--server https://acme-v02.api.letsencrypt.org/directory

上面是通配的子域名, 只能是 a.example.com形式, 不能是 a.b.example.com 形式. 要使用更下级的子域有几个要点:api

  • 通配域名必须使用--manual参数, --webroot等其余参数是互斥的,不能同时使用.
    --manual表示经过DNS的TXT记录进行验证, --webroot经过Web服务器的访问进行验证.
  • 须要在DNS中添加 b.example.com 的A记录, 这样在 Let's encrypt 发起挑战的时候才能解析到这个域名.
  • 须要添加TXT记录 _acme-challenge.b.example.com
    设置了TXT记录后先别急着回车. 先手工验证一下TXT记录有咩有生效浏览器

    dig -t txt _acme-challenge.b.example.com

两个API接口

上面一个是正式的. 签发的证书是浏览器信任的, 下面一个仅用于测试. 咱们能够看到它的名字是Fake LE Root X1服务器

Fake 的意思本身百度.

clipboard.png

安装certbot命令行

进入 https://certbot.eff.org/, 选择你的系统, 页面会自动输出对应的各类系统的安装方式.dom

clipboard.png

Ubuntu 16.04 的安装命令以下:测试

$ sudo apt-get update
$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:certbot/certbot
$ sudo apt-get update
$ sudo apt-get install certbot

流水帐

1.建立 b.example.com 的A记录
2.执行命令申请通配域名(三级域名)spa

certbot certonly --manual \
-d '*.b.exampple.com' \
--agree-tos \
--email domain@example.com \
--server https://acme-v02.api.letsencrypt.org/directory

3.输入两次Y, 确认了两次, 终端输出以下形式的东西, 别敲回车命令行

_acme-challenge.b.example.com with the following value:

ZaUsqkBE109SZMDZheM3UUXA-iw6dukTsixXoG_QrSE

4.建立TXT记录
5.验证TXT记录是否生效code

dig -t txt _acme-challenge.b.example.com

6.TXT生效后敲回车进行DNS的TXT验证server

成功后

你会看到签发给你的证书的域名是这样的 *.b.example.com, 成功以后, 就能够随便添加你的三级域名了.

x.b.example.com
y.b.example.com
z.b.example.com

clipboard.png

注意事项

必定注意使用测试API接口先进行测试. Let's encrypt 失败次数过多会屏蔽你一段时间, 防止滥用.

结语

总的来讲, 通配域名减小了为不一样的子域名申请不一样证书的麻烦. 同时申请过程也比配置Web服务器的验证方式要简单. 只须要修改DNS相关的解析记录就能够了. 比之前方便了很多.

相关文章
相关标签/搜索