如何在Ubuntu 20.04云服务器上安装Let's Encrypt的SSL证书?

  • 发布时间:2021-12-03 09:35:04
  • 阅读次数:1651

Let's Encrypt是一家自动化的免费TLS/SSL证书颁发机构,由ISRG(互联网安全研究组织)提供这项服务。这篇文章讲解了如何在Ubuntu 20.04云服务器上安装Let's Encrypt的SSL证书,适用于Apache或Nginx两种Web服务器。安装完成后,Web服务器将拥有一个合法的SSL证书,并且能把HTTP请求重定向到HTTPS。

安装Certbot

确认snapd为最新版本:

$ sudo snap install core; sudo snap refresh core

删除残留的Certbot:

$ sudo apt-get remove certbot

使用snap安装Certbot:

$ sudo snap install --classic certbot

创建Certbot的链接:

$ sudo ln -s /snap/bin/certbot /usr/bin/certbot

安装SSL证书

运行Certbot安装SSL证书。Certbot命令各选项及含义如下:

  • --apache:使用Apache服务器
  • --nginx:使用Nginx服务器
  • --redirect:重定向HTTP请求到HTTPS
  • -d example.com -d www.example.com:安装多域名证书(SAN),最多支持100个域名
  • -m admin@example.com:设置证书的通知邮件
  • --agree-tos:同意服务条款

还可以使用certbot --help命令获取更多帮助信息。

1、Apache下安装SSL证书:

# certbot --apache --redirect -d example.com -d www.example.com -m admin@example.com --agree-tos

2、Nginx下安装SSL证书:

# nano /etc/nginx/conf.d/default.conf

更改server_name为实际域名:

server {
    server_name  example.com www.example.com;

执行安装命令:

# certbot --nginx --redirect -d example.com -d www.example.com -m admin@example.com --agree-tos

设置自动续订

Let's Encrypt证书的有效期是90天。Certbot会更新系统的定时任务crontab,实现自动续订证书。

确认计时器状态:

# systemctl list-timers | grep 'certbot\|ACTIVATES'

确认定时任务状态:

# ls -l /etc/cron.d/certbot

确认续订执行正常:

# certbot renew --dry-run

以上就是使用Certbot安装Let's Encrypt证书的方法,更多信息可参考Certbot官方文档。

https://certbot.eff.org/instructions

【全文完】

< 上一篇:如何在CentOS 7云服务器上使用CSF防火墙? 下一篇:如何在CentOS 7云服务器上安装Let's Encrypt的SSL证书? >