如何在 AlmaLinux 8 上安装 Let’s Encrypt SSL with LEMP

在本教程中,我们将向您展示如何在 AlmaLinux 8 上使用 LEMP 安装 Let’s Encrypt SSL。对于那些不知道的人,Let’s Encrypt 是适合您的免费 SSL 选项。 Let’s Encrypt 可以通过 Certbot 进行签名,Certbot 是一个免费的开源软件工具,用于自动颁发 SSL 证书。

本文假设您至少具备 Linux 的基本知识,知道如何使用 shell,最重要的是,您将网站托管在自己的 VPS 上。 安装非常简单,假设您在 root 帐户下运行,如果不是,您可能需要添加 ‘sudo‘ 到命令以获取 root 权限。 我将向您展示在 AlmaLinux 8 上使用 LEMP 逐步安装免费 SSL 证书。您可以按照 CentOS 和 Rocky Linux 的相同说明进行操作。

在 AlmaLinux 8 上安装 Let’s Encrypt SSL with LEMP

第 1 步。首先,让我们首先确保您的系统是最新的。

sudo dnf update sudo dnf install epel-release mod_ssl

步骤 2. 安装 LEMP 服务器。

需要 AlmaLinux LEMP 服务器。 如果您没有安装 LEMP,您可以在此处按照我们的指南进行操作。

步骤 3. 安装 Certbot。

现在我们安装用于创建 Let’s Encrypt 证书的 Certbot 客户端:

sudodnf installcertbot python3-certbot-nginx

要验证 Certbot 安装运行:

certbot --version

第 4 步:在 AlmaLinux 上安装免费的 SSL Let’s Encrypt。

现在我们使用 Certbot 命令来颁发 Let’s Encrypt 证书。 代替 your-domain.com[email protected] 使用您的域名和电子邮件:

certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email [email protected] -d your-domain.com

在安装过程中,这将生成一组您需要回答的提示。 如果一切顺利,您应该会收到以下消息:

Requesting a certificate for yourdomain.com Performing the following challenges: http-01 challenge for your-domain.com Waiting for verification... Cleaning up challenges Subscribe to the EFF mailing list (email: [email protected]).  IMPORTANT NOTES:  - Congratulations! Your certificate and chain have been saved at:    /etc/letsencrypt/live/your-domain.com/fullchain.pem    Your key file has been saved at:    /etc/letsencrypt/live/your-domain.com/privkey.pem    Your certificate will expire on 2021-08-25. 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

此时,当您使用完 Certbot 后,您可以检查您的 SSL 证书状态。 在您的网络浏览器中键入以下链接:

https://www.ssllabs.com/ssltest/analyze.html?d=your-domian.com

步骤 5. 配置防火墙。

现在添加防火墙规则以允许连接以及 HTTP(端口 80)和 HTTPS(端口 443)流量:

sudo firewall-cmd --permanent --add-port=80/tcp --zone=public sudo firewall-cmd --permanent --add-port=443/tcp --zone=public sudo firewall-cmd --reload

恭喜! 您已成功安装免费 SSL 证书。 感谢您使用本教程在您的 AlmaLinux 8 系统上安装 Certbot。 如需更多帮助或有用信息,我们建议您查看 Certbot 官方网站.