溫馨提示×

Nginx SSL證書更新Debian步驟

小樊
46
2025-06-24 06:43:50
欄目: 云計算

在Debian系統上更新Nginx SSL證書的步驟如下:

1. 備份現有證書和密鑰

在操作前,務必備份現有證書和密鑰文件:

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

2. 獲取新的SSL證書

使用Certbot自動更新證書(推薦)

  • 安裝Certbot和python3-certbot-nginx包(如果尚未安裝):
sudo apt update
sudo apt install certbot python3-certbot-nginx
  • 使用Certbot獲取并配置證書:
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

3. 重新加載Nginx配置

更新證書后,重新加載Nginx配置:

sudo nginx -t # 檢查配置文件語法
sudo systemctl reload nginx # 重新加載Nginx服務

4. 驗證更新

使用瀏覽器訪問你的網站,確認新的SSL證書已生效,無警告或錯誤。

以上就是在Debian系統上更新Nginx SSL證書的步驟。如果有任何問題,請參考Certbot官方文檔或尋求社區支持。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女