安装 Certbot
Certbot 用来自动申请和更新 SSL 证书,这也是为了 HTTPS。
sudo yum install epel-release
sudo yum install certbot
# 安装完成后,使用以下命令查看 certbot 安装的版本
certbot --version
使用Certbot来生成证书
certbot certonly -d *.使用自己的域名替换.com -d 使用自己的域名替换.com --manual --preferred-challenges dns
certonly: 这个子命令表示只获取证书,而不会自动安装或配置它。
-d *.使用自己的域名替换.com: 这个参数指定了你要获取证书的域名,其中*.使用自己的域名替换.com表示获取一个通配符证书,适用于该域名下的所有子域名。
-d 使用自己的域名替换.com:这个参数是将主域名也加入到证书中,否则会导致子域名正常了,主域名提示证书不合法。
--manual: 这个参数表示手动模式。在手动模式下,你需要按照指示手动完成一些步骤,例如DNS验证。
--preferred-challenges dns: 这个参数指定了首选的验证方式为DNS验证。DNS验证需要你在你的DNS管理后台添加一个TXT记录来验证你对域名的所有权。
certbot certonly -d *.baidu.com -d baidu.com --manual --preferred-challenges dns
输入后会要求你在域名解析中加入txt记录类型,并且地址已经打印出来了
此时按下Enter键就会出现申请成功
//此时运行certbot certificates, 即可查看申请成功的证书信息
[root@master directory]# certbot certificates
Saving debug log to /var/log/letsencrypt/letsencrypt.log
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Found the following certs:
Certificate Name: dashuzi.club
Serial Number: 48026e232cb7514b0229c83be86943d8c36 //记录值
Key Type: RSA //加密算法
Domains: *.dashuzi.club //dns域名列表
Expiry Date: 2025-04-22 06:36:54+00:00 (VALID: 89 days) //过期时间
Certificate Path: /etc/letsencrypt/live/dashuzi.club/fullchain.pem //证书
Private Key Path: /etc/letsencrypt/live/dashuzi.club/privkey.pem //密钥
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
后续在nginx部署站点的时候,选择此证书目录即可。