CentOS環(huán)境部署SSL證書實(shí)現(xiàn)HTTPS加密
準(zhǔn)備工作
部署前需確保滿足以下條件:
- 已安裝CentOS 7/8操作系統(tǒng)
- 擁有服務(wù)器root權(quán)限
- 域名已完成DNS解析
- 80/443端口開放訪問
Certbot工具安裝
EPEL倉(cāng)庫(kù)啟用
yum install epel-release -y
Certbot安裝命令
yum install certbot python3-certbot-nginx -y # Nginx版本
yum install certbot python3-certbot-apache -y # Apache版本
SSL證書申請(qǐng)
自動(dòng)驗(yàn)證模式(推薦)
certbot --nginx # Nginx服務(wù)器
certbot --apache # Apache服務(wù)器
手動(dòng)驗(yàn)證模式
certbot certonly --manual -d example.com -d www.example.com
Web服務(wù)器配置
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>
證書自動(dòng)續(xù)期
通過crontab設(shè)置定時(shí)任務(wù):
0 3 * * * /usr/bin/certbot renew --quiet
驗(yàn)證與測(cè)試
- 使用瀏覽器訪問https://example.com
- 通過SSL Labs測(cè)試評(píng)分:SSL Server Test
- 檢查證書有效期:certbot certificates
常見問題處理
證書續(xù)期失敗
解決方案:停止Web服務(wù)后執(zhí)行續(xù)期命令
systemctl stop nginx && certbot renew
混合內(nèi)容警告
確保網(wǎng)站所有資源使用HTTPS協(xié)議加載