在 Ubuntu 上更新 Nginx SSL 證書,您可以使用 Let’s Encrypt 提供的 Certbot 工具。以下是使用 Certbot 更新 SSL 證書的步驟:
sudo apt update
sudo apt install certbot python3-certbot-nginx
yourdomain.com
替換為您的實際域名:sudo certbot --nginx -d yourdomain.com
Certbot 將嘗試自動配置 Nginx 以使用新的 SSL 證書。按照提示操作,您可能需要輸入電子郵件地址以接收有關證書更新的通知。
如果 Certbot 提示您是否要重定向 HTTP 流量到 HTTPS,請選擇“是”。
更新完成后,Certbot 將顯示一條消息,說明證書已成功安裝。您還可以使用以下命令檢查證書的有效期:
sudo openssl x509 -in /etc/letsencrypt/live/yourdomain.com/fullchain.pem -noout -dates
sudo systemctl enable certbot.timer
現在,您的 Nginx SSL 證書將在到期前自動更新。如果您需要手動更新證書,只需重新運行第 2 步中的命令即可。