1 背景
在网站服务中,使用 HTTPS 协议可以有效提高安全性,但是需要进行证书的签发。对于大型的网站服务是非常容易的,但对于如个人博客网站等,需要承担一定的证书签发费用。
本文主要提供两种免费签发 HTTPS 证书的方法,供大家学习交流。
2 使用 certbot 生成证书
2.1 生成证书
(1)安装 certbot
# 安装 epel-release 源
$ yum -y install epel-release
# 安装 certbot
$ yum -y install certbot
(2)生成泛域名 *.ecsy.top
证书
# 执行以下命令
$ certbot certonly -d *.ecsy.top --manual --preferred-challenges dns
参数释义:
-d 指定您的泛域名
--manual 表示手动生成证书
--pfeferred-challeges dns 使用 DNS 验证域名归属
(3)此处输入您的邮箱地址
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
(Enter 'c' to cancel): xxxxxx@126.com
(4)输入 Y
同意
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.3-September-21-2022.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
(5)输入 N
不允许共享电子邮件地址
Would you be willing, once your first certificate is successfully issued, 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 our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: N
(6)根据提示进行域名归属认证
Account registered.
Requesting a certificate for *.ecsy.top
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name:
_acme-challenge.ecsy.top.
with the following value:
aQyGqKJecDh9ud-TuQlH-N70DW_RF6KtBRx_EZ0vhLI
Before continuing, verify the TXT record has been deployed. Depending on the DNS
provider, this may take some time, from a few seconds to multiple minutes. You can
check if it has finished deploying with aid of online tools, such as the Google
Admin Toolbox: https://toolbox.googleapps.com/apps/dig/#TXT/_acme-challenge.ecsy.top.
Look for one or more bolded line(s) below the line ';ANSWER'. It should show the
value(s) you've just added.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue
根据返回信息提示,在您的域名提供商控制台,添加一条 DNS TXT 解析记录:
注意:
添加 DNS 解析记录后,需要等待一段时间进行同步,才能解析成功,可以使用 nslookup -q=TXT _acme-challenge.test.com. 尝试解析,或在域名提供商控制台进行生效检测。
检测成功后,按 Enter 键继续。
(7)成功签发证书
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/ecsy.top/fullchain.pem
Key is saved at: /etc/letsencrypt/live/ecsy.top/privkey.pem
This certificate expires on 2024-01-06.
These files will be updated when the certificate renews.
# 查看证书文件
$ ls /etc/letsencrypt/live/ecsy.top/
fullchain.pem # 证书
privkey.pem # 私钥
2.2 将证书添加到 Web 服务配置文件中
# 此处使用 nginx
$ vim /etc/nginx/nginx.conf
server {
listen 443 ssl http2;
ssl_certificate "/etc/letsencrypt/live/ecsy.top/fullchain.pem";
ssl_certificate_key "/etc/letsencrypt/live/ecsy.top/privkey.pem";
......
}
2.3 常见问题
2.3.1 仍然提示连接不安全
在配置好证书后访问网站时,可能仍然出现连接不安全的提示,如下图所示:
原因已经说的非常清楚了,此处我使用 escy.top
这个域名来访问,并没有使用泛域名,因此提示:“此服务器无法证明它是 ecsy.top
;它的安全证书来自 *.ecsy.top
。这可能是由错误配置或者有攻击者截获你的连接而导致的。”
为此,我们需要再次为 ecsy.top
生成证书,重新执行上文所述的证书生成步骤并配置到 Web 服务中即可,此时的生成证书命令将变为:
# 执行以下命令
$ certbot certonly -d ecsy.top --manual --preferred-challenges dns
2.3.2 证书有效期
证书有效期为 3 个月,证书到期前您可以手动按以上步骤重新签发,也可以使用官方提供的自动续期方案。
NEXT STEPS:
- This certificate will not be renewed automatically. Autorenewal of --manual certificates requires the use of an authentication hook script (--manual-auth-hook) but one was not provided. To renew this certificate, repeat this same certbot command before the certificate's expiry date.
3 使用图形化界面生成证书
如果您觉得使用 certbot 命令行工具生成证书比较繁琐,且不直观,可以使用网页来生成证书。
比较推荐这个网站:来此加密 - Let's Encrypt 在线免费申请SSL证书 (osfipin.com):
此网站有如下特点:
- 提供了直观的操作界面,引导流程也非常详细易懂。
- 其原理与 certbot 命令行工具类似,都需要使用 DNS TXT 记录来验证域名的归属。
- 在证书生成后,可以进行下载使用。
- 证书有效期仍然是 3 个月,可以选择到期前通过短信提醒,重新续期。
- 可以在账户中方便管理自己的证书。
由于操作难度不大,在此不作流程演示。
评论