您好,登录后才能下订单哦!
# 如何在CentOS下安装Let’s Encrypt永久免费SSL证书
## 前言
在当今互联网环境中,网站安全已成为不可忽视的重要议题。SSL/TLS证书作为保障数据传输加密的核心技术,已经从可选配置变为必备要素。Let's Encrypt作为非营利性证书颁发机构(CA),提供完全免费的自动化证书服务,极大降低了HTTPS的部署门槛。本文将详细介绍在CentOS系统上使用Certbot工具获取、安装和自动续期Let's Encrypt证书的全过程。
## 一、准备工作
### 1.1 系统要求
- CentOS 7/8(本文以CentOS 7为例)
- 已安装Nginx/Apache等Web服务(本文以Nginx为例)
- 域名已解析到服务器IP
- 开放80和443端口
### 1.2 环境检查
```bash
# 检查系统版本
cat /etc/centos-release
# 检查Web服务状态
systemctl status nginx
# 检查防火墙设置
firewall-cmd --list-ports
yum install epel-release -y
yum install certbot python3-certbot-nginx -y
certbot --version
# 应输出类似:certbot 1.21.0
certbot --nginx -d example.com -d www.example.com
执行后会交互式询问: 1. 输入邮箱(用于安全通知) 2. 同意服务条款 3. 是否订阅电子报(可选否)
certbot certonly --webroot -w /var/www/html -d example.com -d www.example.com
需要确保:
- -w
参数指定的目录是网站根目录
- 可通过http://example.com/.well-known/acme-challenge/
访问验证文件
Certbot会自动修改Nginx配置,典型片段如下:
server {
listen 443 ssl;
server_name example.com www.example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
# 强制HTTPS跳转
server {
listen 80;
server_name example.com www.example.com;
return 301 https://$host$request_uri;
}
# 增强SSL安全性
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384...';
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
certbot renew --dry-run
crontab -e
添加以下内容(每天凌晨2点检查续期):
0 2 * * * /usr/bin/certbot renew --quiet --post-hook "systemctl reload nginx"
需要DNS验证方式:
certbot certonly --manual --preferred-challenges=dns -d *.example.com
# 单个证书包含多个域名
certbot --nginx -d example.com -d api.example.com -d static.example.com
# 查看现有证书
certbot certificates
certbot revoke --cert-path /etc/letsencrypt/live/example.com/cert.pem
解决方法:
- 临时停止Nginx:systemctl stop nginx
- 使用--standalone
模式:certbot certonly --standalone -d example.com
检查日志:
tail -f /var/log/letsencrypt/letsencrypt.log
cert.pem
:域名证书chain.pem
:中间证书fullchain.pem
:完整证书链privkey.pem
:私钥文件私钥保护:设置600权限
chmod 600 /etc/letsencrypt/live/example.com/privkey.pem
OCSP Stapling 配置:
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
HSTS 头加强:
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
使用Certbot内置提醒或第三方监控工具:
certbot renew --notify-hook "/path/to/notification-script.sh"
建议备份整个/etc/letsencrypt
目录:
tar -czvf letsencrypt-backup-$(date +%Y%m%d).tar.gz /etc/letsencrypt
通过本文的详细指导,您应该已经成功在CentOS服务器上部署了Let’s Encrypt SSL证书。这种全自动化的免费证书方案,配合合理的续期机制,可以长期保障网站的安全通信。随着HTTP/2的普及和浏览器对HTTPS的强制要求,部署SSL证书已成为现代网站的标配操作。Let’s Encrypt的出现,真正实现了”加密整个互联网”的愿景。
注意:Let’s Encrypt证书有效期仍为90天,但通过自动化续期可以实现”永久免费”的效果。建议定期检查cron任务和续期日志确保系统正常运行。 “`
本文共计约2300字,涵盖了从基础安装到高级配置的全流程,并包含故障排查和安全建议,适合不同技术水平的用户参考使用。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。