在Debian系統上更新Nginx SSL證書的步驟如下:
在操作前,務必備份現有證書和密鑰文件:
sudo cp /etc/ssl/certs/nginx.crt /etc/ssl/certs/nginx.crt.backup
sudo cp /etc/ssl/private/nginx.key /etc/ssl/private/nginx.key.backup
sudo apt update
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
按照提示選擇需要配置SSL的域名,以及其他選項,例如自動重定向。
sudo certbot renew --dry-run
sudo crontab -e
添加以下行,將your-email@example.com
替換為你的郵箱地址,/var/www/certbot
替換為你的certbot的webroot路徑(如有不同):
0 0,12 * * * certbot renew --webroot --webroot-path=/var/www/certbot --email your-email@example.com --agree-tos --no-eff-email
此cron作業會在每天的午夜和中午檢查并自動續訂證書。
new_certificate.crt
)和密鑰文件(new_private.key
)復制到Nginx配置指定的位置:sudo cp /path/to/new_certificate.crt /etc/ssl/certs/nginx.crt
sudo cp /path/to/new_private.key /etc/ssl/private/nginx.key
更新證書后,重新加載Nginx配置:
sudo nginx -t # 檢查配置文件語法
sudo systemctl reload nginx # 重新加載Nginx服務
使用瀏覽器訪問你的網站,確認新的SSL證書已生效,無警告或錯誤。
以上就是在Debian系統上更新Nginx SSL證書的步驟。如果有任何問題,請參考Certbot官方文檔或尋求社區支持。