certbot申请泛域名证书Let's Encrypt免费证书

一.什么是泛域名证书?

例如:*.xxx.cn 也就是这个证书可以给某个域名的所有二级域名使用,就叫做泛域名证书(也称作通配符证书)。
Let's Encrypt 官方推荐我们使用certbot 脚本申请证书(当然也可以使用acme.sh等方式),
以下是申请步骤基于Debian10 python3.7.3如果你在操作过程中遇到什么报错,请多考虑python工具包的版本问题之类的。
Let's Encrypt自2018年开始支持申请泛域名证书,相比于单域名证书,泛域名证书更利于日常的维护。
Let's Encrypt泛域名证书

二.CentOS7.x 上 安装cerbot

yum -y install epel-release
yum -y install certbot

三.certbot官方

https://certbot.eff.org/
在centos7以上系统安装好ertbot服务后,直接上代码:

certbot certonly --preferred-challenges dns --manual -d *.baidu.com --server https://acme-v02.api.letsencrypt.org/directory --register-unsafely-without-email

certbot命令参数含义:
--manual:手动模式获取/安装证书。
--agree-tos:同意使用Let's Encrypt服务条款
--server:用于指定证书签发机构的ACME协议服务器的URL
--register-unsafely-without-email:用于在不提供电子邮件地址的情况下向 Let's Encrypt 注册新的账户
--preferred-challenges:用于指定ACME挑战的优先级顺序。
ACME挑战是获取SSL证书的过程中必须通过的验证过程,其中包括HTTP-01,DNS-01和TLS-ALPN-01三种类型的挑战。
通过--preferred-challenges选项,可以告诉certbot命令要按照哪种挑战的优先级顺序来验证您的域名。
默认情况下,certbot将首选HTTP-01挑战,因为它是最常用的一种验证方式。
但是,如果服务器无法接收来自ACME服务器的传入连接,
则可以通过--preferred-challenges dns选项将优先级更改为DNS-01挑战。

执行上面命令后,结果如下:

// certbot 生成证书 
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 xx.cn
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name
_acme-challenge.xx.cn with the following value:
nI0DhzH-vn0W7STVuLi2O-oIKuFNlqQx5EnjB-zewvs       -----关键这里要添加到阿里云上解析txt值
Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue   
#让你的二级域名_acme-challenge.xx.cn用TXT方式
#解析到nI0DhzH-vn0W7STVuLi2O-oIKuFNlqQx5EnjB-zewvs
#可以用dig -t txt _acme-challenge.xx.cn验证解析是否生效, -------如无dig命令需要用yum install bind-utils
#然后按下Enter通过验证。
#也可以用nslookup命令来验证。
Waiting for verification...
Cleaning up challenges
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/xx.cn/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/xx.cn/privkey.pem
Your cert will expire on 2021-04-26. To obtain a new or tweaked
version of this certificate in the future, simply run certbot
again. To non-interactively renew *all* of your certificates, run
"certbot 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

# ll  /etc/letsencrypt/live/www.example.com/

total 4
lrwxrwxrwx 1 root root  51 Sep 28 14:13 cert.pem -> ../../archive/www.example.com/cert1.pem
lrwxrwxrwx 1 root root  52 Sep 28 14:13 chain.pem -> ../../archive/www.example.com/chain1.pem
lrwxrwxrwx 1 root root  56 Sep 28 14:13 fullchain.pem -> ../../archive/www.example.com/fullchain1.pem
lrwxrwxrwx 1 root root  54 Sep 28 14:13 privkey.pem -> ../../archive/www.example.com/privkey1.pem
-rw-r--r-- 1 root root 692 Sep 28 14:13 README

四.至此证书申请成功!

用到的是这2个 根据自己的需求转换

fullchain.pem privkey.pem ------可以直接改后缀名pem改为crt或者key

替换nginx 中的 ssl 配置文件
nginx -s reload

要续期的话

执行certbot-auto renew就可以了

posted @ 2024-07-14 03:37  記憶や空白  阅读(70)  评论(0编辑  收藏  举报