CentOS环境部署SSL证书实现HTTPS加密
准备工作
部署前需确保满足以下条件:
- 已安装CentOS 7/8操作系统
- 拥有服务器root权限
- 域名已完成DNS解析
- 80/443端口开放访问
Certbot工具安装
EPEL仓库启用
yum install epel-release -y
Certbot安装命令
yum install certbot python3-certbot-nginx -y # Nginx版本
yum install certbot python3-certbot-apache -y # Apache版本
SSL证书申请
自动验证模式(推荐)
certbot --nginx # Nginx服务器
certbot --apache # Apache服务器
手动验证模式
certbot certonly --manual -d example.com -d www.example.com
Web服务器配置
Nginx配置示例
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
# 其他配置...
}
Apache配置示例
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem
# 其他配置...
</VirtualHost>
证书自动续期
通过crontab设置定时任务:
0 3 * * * /usr/bin/certbot renew --quiet
验证与测试
- 使用浏览器访问https://example.com
- 通过SSL Labs测试评分:SSL Server Test
- 检查证书有效期:certbot certificates
常见问题处理
证书续期失败
解决方案:停止Web服务后执行续期命令
systemctl stop nginx && certbot renew
混合内容警告
确保网站所有资源使用HTTPS协议加载