跳转到主要内容
Chinese, Simplified

先决条件
以 sudo 身份访问服务器。
正确配置的域和虚拟主机。
如果您具备这些先决条件,那么让我们开始吧。

目录

  • 安装依赖
  • 安装 Certbot——让我们加密客户端
  • 生成 SSL 证书
  • 设置自动续订
  • 检查证书状态
  • 删除 Certbot 证书

第 1 步:安装依赖项


要安装 Certbot,我们需要安装 EPEL 存储库和 mod_ssl。 运行此命令以安装两者:

sudo  yum install -y epel-release mod_ssl


第 2 步:安装 Certbot——让我们加密客户端


从 EPEL 存储库,让我们安装 Certbot 客户端:

sudo yum install -y python-certbot-apache


第 3 步:生成 SSL 证书


我们有必要的模块来生成 Let's Encrypt SSL。 要为单个域生成证书,请运行以下命令:

sudo certbot --apache -d example.com


要为多个域或子域生成 SSL,请运行以下命令:

sudo certbot --apache -d example.com -d www.example.com


此处,example.com 是基本域。

您还可以通过选择域名来生成 SSL 证书。为此,请运行以下命令以显示所有托管域:

sudo certbot --apache


选择一个选项并根据需要运行该命令。安装成功后,您将看到类似于此消息的消息:

重要笔记:

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 2019-10-24. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. 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


第 4 步:设置自动续订


我们知道 Let's Encrypt 证书的有效期为 90 天。但是我们可以很容易地更新证书。只需在到期日期之前运行此命令:

sudo certbot renew


我们还可以设置一个 cronjob 来自动更新。打开定时任务:

crontab -e


然后添加这一行:

0 0 * * 1 /usr/bin/certbot renew >> /var/log/sslrenew.log


第 5 步:检查证书状态


我们已经成功安装了 Let's Encrypt SSL。现在让我们通过访问此 URL 来检查 SSL 证书的状态:

https://www.ssllabs.com/ssltest/analyze.html?d=example.com


第 6 步:删除 Certbot 证书


要删除证书,我们必须运行以下命令:

# 选择域名


sudo certbot delete

# 直接分配域名


sudo certbot delete --cert-name example.com


 文章结束了。谢谢阅读

原文:https://shouts.dev/centos-7-install-lets-encrypt-ssl-on-apache-server

本文:https://jiagoushi.pro/centos-7-install-lets-encrypt-ssl-apache-server

Article
知识星球
 
微信公众号
 
视频号