\
为了在 CentOS 上为您的域名安装免费的 SSL 证书并启用 HTTPS,您可以使用 Let’s Encrypt 提供的免费证书。下面是使用 Certbot 工具在 CentOS 系统上为您的域名安装和配置 Let’s Encrypt SSL 证书的步骤:
- 安装 EPEL 仓库
Certbot 工具需要 EPEL(Extra Packages for Enterprise Linux)仓库。如尚未安装,请运行以下命令安装 EPEL 仓库:
sudo yum install epel-release
- 安装 Certbot 和 Certbot Nginx 或 Apache 插件
根据您的 web 服务器(Nginx 或 Apache),安装 Certbot 和相应的插件:
对于 Nginx:
sudo yum install certbot python2-certbot-nginx
对于 Apache:
sudo yum install certbot python2-certbot-apache
- 获取 SSL 证书
运行以下命令获取 SSL 证书并配置您的 web 服务器。请确保将 yourdomain.com
替换为您的实际域名。
对于 Nginx:
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
对于 Apache:
sudo certbot --apache -d yourdomain.com -d www.yourdomain.com
- 检查证书自动续订
Certbot 会尝试自动为您续订 SSL 证书。运行以下命令测试自动续订是否正常工作:
sudo certbot renew --dry-run
- 重启 web 服务器
最后,重启您的 web 服务器以使更改生效。
对于 Nginx:
sudo systemctl restart nginx
对于 Apache:
sudo systemctl restart httpd
完成上述步骤后,您应该能够通过 HTTPS 访问您的域名。您可以在浏览器中输入 https://yourdomain.com
(将 yourdomain.com
替换为您的实际域名)进行测试。请注意,证书的有效期为 90 天,但 Certbot 会尝试在到期前自动续订证书。务必确保自动续订正常工作,以避免证书过期导致的问题。