摒弃世俗浮躁
追求技术精湛

免费申请 Let's Encrypt SSL通配符证书方法(HTTPS)

什么是 Let’s Encrypt?

部署 HTTPS 网站的时候需要证书,证书由 CA 机构签发,大部分传统 CA 机构签发证书是需要收费的,这不利于推动 HTTPS 协议的使用。

Let’s Encrypt 也是一个 CA 机构,但这个 CA 机构是免费的!也就是说签发证书不需要任何费用。

Let’s Encrypt 由于是非盈利性的组织,需要控制开支,他们搞了一个非常有创意的事情,设计了一个 ACME 协议,目前该协议的版本是 v2。

那为什么要创建 ACME 协议呢,传统的 CA 机构是人工受理证书申请、证书更新、证书撤销,完全是手动处理的。而 ACME 协议规范化了证书申请、更新、撤销等流程,只要一个客户端实现了该协议的功能,通过客户端就可以向 Let’s Encrypt 申请证书,也就是说 Let’s Encrypt CA 完全是自动化操作的。

任何人都可以基于 ACME 协议实现一个客户端,官方推荐的客户端是Certbot。

Certbot Github地址

什么是通配符证书?

在没有出现通配符证书之前,Let’s Encrypt 支持两种证书。

  1. 单域名证书:证书仅仅包含一个主机。
  2. SAN 证书:一张证书可以包括多个主机(Let’s Encrypt 限制是 20),也就是证书可以包含下列的主机:www.example.com、www.example.cn、blog.example.com 等等。

证书包含的主机可以不是同一个注册域,注册域就是向域名注册商购买的域名。

如何申请 Let’s Encrypt 通配符证书

一、准备环境(Linux CentOS 7.4示例)

#安装git
yum -y install git

#获取certbot
git clone https://github.com/certbot/certbot.git

二、申请证书

通过Certbot获取证书:

./certbot-auto certonly  -d *.github.xin --manual --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory

参数说明:

  • certonly,表示安装模式,Certbot 有安装模式和验证模式两种类型的插件。
  • –manual 表示手动安装插件,Certbot 有很多插件,不同的插件都可以申请证书,用户可以根据需要自行选择
  • -d 为那些主机申请证书,如果是通配符,输入 *.github.xin(替换为你自己的域名)
  • –preferred-challenges dns,使用 DNS 方式校验域名所有权
  • –server,Let’s Encrypt ACME v2 版本使用的服务器不同于 v1 版本,需要显式指定。

2020年6月4日补充:
github.xin 不在通配符范围之内,如有必要请参考下面语法来生成证书

./certbot-auto certonly -d *.github.xin -d github.xin --manual --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory

 

接下来会问你是否同意Let’s Encrypt的协议:(Y同意/N不同意)

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator manual, Installer None
Obtaining a new certificate
Performing the following challenges:
dns-01 challenge for github.xin

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NOTE: The IP of this machine will be publicly logged as having requested this
certificate. If you're running certbot in manual mode on a machine that is not
your server, please ensure you're okay with that.

Are you OK with your IP being logged?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y

根据要求去做TXT类型的域名解析:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name
_acme-challenge.github.xin with the following value:

j5yEHAGPVmJ5_eNOJYPqD16RHTpx_quLD_oTegvAnGg

Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue
  • 主机记录:_acme-challenge.github.xin
  • 类型:TXT
  • 记录值:j5yEHAGPVmJ5_eNOJYPqD16RHTpx_quLD_oTegvAnGg

这个一般都是即时生效,添加完成等几秒再回到服务器按回车就可以了

Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/github.xin/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/github.xin/privkey.pem
   Your cert will expire on 2018-11-29. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot-auto
   again. To non-interactively renew *all* of your certificates, run
   "certbot-auto renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

证书申请完成了,结构如下 :

/etc/letsencrypt/archive/github.xin
├── cert.pem
├── chain.pem
├── fullchain.pem
└── privkey.pem

三、检验证书

执行命令:

openssl x509 -in ./cert.pem -noout -text

结果

...
            X509v3 Subject Alternative Name:
                DNS:*.github.xin
...

证书申请完成,可以拿去使用了。

赞(4) 打赏
未经允许不得转载:时光日记 » 免费申请 Let's Encrypt SSL通配符证书方法(HTTPS)

评论 抢沙发

评论前必须登录!

 

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫

微信扫一扫

登录

找回密码

注册