美文网首页
免费TLS--Let's Encrypt 使用说明

免费TLS--Let's Encrypt 使用说明

作者: 胖子捏肚子 | 来源:发表于2024-07-19 12:51 被阅读0次
  • Let's Encrypt:这是一个由非营利性组织互联网安全研究小组(ISRG)提供的免费、自动化和开放的证书颁发机构。它为众多网站提供 TLS 证书,其免费证书的签发/续签可以通过脚本自动化完成。Let's Encrypt 免费证书的有效期通常为90天。官方网站为:https://letsencrypt.org/zh-cn/

根据官网https://letsencrypt.org/zh-cn/getting-started/的说明,申请免费的TLS需要三个条件
1.你有一个域名并且已经绑定了你的云主机ip
2.你有云主机的ssh登录权限
3.你的ssh账户有sudo权限

如果上面的需求你都满足了,那么就可以按照流程申请免费的TLS了
流程是 下载安装snapd-->用snapd下载安装certbot-->利用certbot申请TLS证书并自动续约

下载安装snapd,官网 https://snapcraft.io/docs/installing-snapd

#安装snapd
sudo yum install snapd
#Once installed, the systemd unit that manages the main snap communication socket needs to be enabled
sudo systemctl enable --now snapd.socket
#enable classic snap support
sudo ln -s /var/lib/snapd/snap /snap
#这里需要重启一下才能保证后续的正常下载
sudo systemctl restart snapd.service

用snapd下载安装certbot,并申请证书

#安装certbot
sudo snap install --classic certbot
#添加软连接
sudo ln -s /snap/bin/certbot /usr/bin/certbot
#运行此命令以获取证书,并让 Certbot 自动编辑您的 nginx 配置以提供它,只需一步即可打开 HTTPS 访问
sudo certbot --nginx
#如果您感觉更保守,并希望手动更改 nginx 配置,请运行此命令
sudo certbot certonly --nginx
#系统上的 Certbot 软件包附带一个 cron 作业或 systemd 计时器,它将在证书过期之前自动续订证书。除非您更改配置,否则您无需再次运行 Certbot。
#您可以通过运行以下命令来测试证书的自动续订
sudo certbot renew --dry-run

我使用的是sudo certbot certonly --nginx,所以我运行后会得到以下提示

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/yourwebsite.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/yourwebsite.com/privkey.pem
This certificate expires on 2023-12-26.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

现在可以配置你的nginx后开始使用https了。
这里只展示了nginx的使用样例,如果要用其他方式配置TLS可以去certbot官网查看对应的使用方法。

相关文章

网友评论

      本文标题:免费TLS--Let's Encrypt 使用说明

      本文链接:https://www.haomeiwen.com/subject/gvmdhjtx.html