「Certbot」- 在内网中申请证书的方法 @20210225

问题描述

在申请证书时,按照 Certbot 官方指引,需要公网服务器并且需要 HTTP 站点在线。这主要是为了完成质询,以证明域名所有权。

可是有时我们并没有公网服务器,更没有对外站点,我们希望在内网测试环境中能够使用 HTTPS 证书,那我们应该如何申请证书呢?

解决办法

可以使用 DNS 质询方法…………在申请证书时,选择DNS质询,申请过程中会提示你添加域名解析。

第一步、开始申请证书

执行如下命令开始申请证书,按照提示操作即可:

certbot certonly --manual --preferred-challenges dns -d example.com

在收到类似如下提示时进入下一步,添加 TXT 解析记录:

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

667drNmQL3vX6bu8YZlgy0wKNBlCny8yrjF1lSaUndc

Once this is deployed,
Press ENTER to continue

第二步、添加解析记录

根据上面提示,添加名为 _acme-challenge.example.comTXT 记录,将 667drNmQL3vX6bu8YZlgy0wKNBlCny8yrjF1lSaUndc设置为记录值。

注意,由于DNS记录不会马上生效,所以稍后再按回车键。可以使用 dig +short -t txt _acme-challenge.example.com 命令验证DNS是否生效。

第三步、按下回车键

在确认 DNS 记录生效之后,按下回车键将会收到证书申请成功的提示(类似如下内容):

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/example.com/privkey.pem
   Your cert will expire on 2020-03-11. 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

第四步、使用证书

不同于其他方法,该方法只能申请证书,你需要手动修改Web服务器配置以使用证书。

第五步、证书自动续期

证书有效期为 90 天,需要在定时任务中使用 certbot renew 命令重新续期证书,有关内容参考官方文档。但是还需要附加操作,可以参考 ERR - manual plugin is not working 笔记。

附加说明

在腾讯云中,如果 HTTP 站点的域名没有备案,则在使用 HTTP 质询时会失败(因为未备案的HTTP站点会被重定向)。此时(1)可以使用DNS质询,只申请证书,(2)然后在使用--nignx或者其他选项,对于已经存在的证书,他会提示你安装证书。

相关文章

「Certbot」- 安装
「Certbot」- ImportError: 'pyOpenSSL' module missing required functionality
「Certbot」- SERVFAIL looking up CAA for
「Certbot」- The manual plugin is not working
「Certbot」- ocsp.int-x3.letsencrypt.org Read timed out

参考文献

Linux command to inspect TXT records of a domain
Let's Encrypt Server Certificate via DNS Challenge
How to use Let's Encrypt DNS challenge validation?

猜你喜欢

转载自blog.csdn.net/u013670453/article/details/114077571