在当今互联网环境中,为网站启用 HTTPS 已成为基本安全要求。本文将详细讲解如何在 RockyLinux 系统上配置 SSL证书,无论你是使用 Apache 还是 Nginx,都能轻松完成。我们将使用免费且广受信任的 Let's Encrypt 证书服务,全程命令清晰、步骤明确,小白也能看懂!

在开始之前,请确保你已完成以下准备:
Certbot 是 Let's Encrypt 官方推荐的自动化工具,可帮助我们申请和续期 SSL 证书。
1. 启用 EPEL 仓库(如未启用):
sudo dnf install -y epel-release
2. 安装 Certbot 及对应插件:
如果你使用的是 Apache:
sudo dnf install -y certbot python3-certbot-apache
如果你使用的是 Nginx:
sudo dnf install -y certbot python3-certbot-nginx
Apache 用户执行:
sudo certbot --apache -d yourdomain.com -d www.yourdomain.com
Nginx 用户执行:
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
注意:将 yourdomain.com 替换为你自己的域名。Certbot 会自动修改 Web 服务器配置文件并启用 HTTPS。如果你不想让 Certbot 自动修改配置,可以只申请证书:
sudo certbot certonly --webroot -w /var/www/html -d yourdomain.com
证书默认保存在 /etc/letsencrypt/live/yourdomain.com/ 目录下,包含以下文件:
cert.pem:服务器证书privkey.pem:私钥fullchain.pem:完整证书链(推荐用于 Web 服务器)打开浏览器,访问 https://yourdomain.com。如果看到地址栏有锁形图标,说明 RockyLinux SSL证书配置 成功!
Let's Encrypt 证书有效期为 90 天,但 Certbot 已默认配置了自动续期任务。你可以通过以下命令测试是否正常:
sudo certbot renew --dry-run
如果输出中没有错误,说明自动续期已配置成功。系统通常通过 systemd timer 或 cron 每天检查并自动续期即将过期的证书。
sudo firewall-cmd --permanent --add-service=https && sudo firewall-cmd --reloadnslookup yourdomain.com 检查 DNS 记录。sudo systemctl status httpd 或 nginx通过本教程,你应该已经成功完成了 RockyLinux HTTPS设置,并启用了由 Let's Encrypt免费SSL 提供的安全加密连接。无论是个人博客还是企业网站,启用 HTTPS 都能提升用户信任度和搜索引擎排名。
如果你使用的是 Nginx 或 Apache,记得根据实际环境调整配置。希望这篇关于 Apache/Nginx SSL安装 的指南对你有所帮助!
本文由主机测评网于2025-12-16发表在主机测评网_免费VPS_免费云服务器_免费独立服务器,如有疑问,请联系我们。
本文链接:https://vpshk.cn/2025128684.html