原文链接:https://blog.csdn.net/hubinqiang/article/details/80313285
快速配置Let’s encrypt通配符证书
使用certbot配置https证书
准备工具:
环境:Cent OS 7
域名:hubinqiang.com、*.hubinqiang.com
步骤1
# 下载
wget https://dl.eff.org/certbot-auto
# 设为可执行权限
chmod u+x certbot-auto
步骤2
./certbot-auto certonly -d "域名1" -d "域名2" --manual --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory
参数说明
-certonly,表示安装模式,Certbot 有安装模式和验证模式两种类型的插件。
-manual,表示手动安装插件,Certbot有很多插件,不同的插件都可以申请证书,用户可以根据需要自行选择。
-d,为哪些主机申请证书,如果是通配符,例输入*.hubinqiang.com(替换为自己的域名)[可以通过多个-d参数添加主机]
-preferred-challenges,使用 DNS 方式校验域名所有权。
-server,Let’s Encrypt ACME v2 版本使用的服务器不同于 v1 版本,需要显示指定。
申请过程需做如下确认
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator manual, Installer None
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): hubinqiang@126.com
-------------------------------------------------------------------------------
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
-------------------------------------------------------------------------------
(A)gree/(C)ancel: A
-------------------------------------------------------------------------------
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about EFF and
our work to encrypt the web, protect its users and defend digital rights.
-------------------------------------------------------------------------------
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
dns-01 challenge for hubinqiang.com
dns-01 challenge for hubinqiang.com
-------------------------------------------------------------------------------
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
-------------------------------------------------------------------------------
在域名 DNS 解析中添加 TXT记录:
-------------------------------------------------------------------------------
Please deploy a DNS TXT record under the name
_acme-challenge.hubinqiang.com with the following value:
kC-QHSWO1LdIeyIs7VQ66sTAyioISnfzIJU0bXgo-Z8
Before continuing, verify the record is deployed.
-------------------------------------------------------------------------------
Press Enter to Continue
-------------------------------------------------------------------------------
Please deploy a DNS TXT record under the name
_acme-challenge.hubinqiang.com with the following value:
6XnGyee8W48QfRl61m_18aRs8rfvn4T8kKzQil0IYw4
Before continuing, verify the record is deployed.
-------------------------------------------------------------------------------
Press Enter to Continue
Waiting for verification...
Cleaning up challenges
显示我两个主机的 TXT 记录有两条,根据要求分别在 DNS 解析中添加两条 TXT 记录,其中一条如下:
注意:若申请了多个主机,需要添加多个 TXT 记录。要求给 _acme-challenge.hubinqiang.com 配置 TXT 记录,在没有确认 TXT 记录生效之前不要回车执行。
确认生效后会有如下提示:
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/hubinqiang.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/hubinqiang.com/privkey.pem
Your cert will expire on 2018-08-12. 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"
- Your account credentials have been saved in your Certbot
configuration directory at /etc/letsencrypt. You should make a
secure backup of this folder now. This configuration directory will
also contain certificates and private keys obtained by Certbot so
making regular backups of this folder is ideal.
- 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/live/hubinqiang.com/ 中可以看到几个文件,
cert.pem、chain.pem、fullchain.pem、privkey.pem,说明已经成功获取证书和密钥。
步骤三配置证书
在nginx中配置的片段
server {
server_name hubinqiang.com;
listen 443 http2 ssl;
ssl on;
ssl_certificate /etc/letsencrypt/live/hubinqiang.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/hubinqiang.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/hubinqiang.com/chain.pem;
重启nginx查看效果
步骤四证书更新
Let’s encrypt 的免费证书默认有效期为 90 天,到期后如果要续期可以执行:
certbot-auto renew