在Ubuntu上設置Let’s Encrypt自動續期非常簡單
sudo apt update
sudo apt install certbot python3-certbot-apache
如果你使用的是Nginx服務器,請安裝certbot-nginx
:
sudo apt install certbot python3-certbot-nginx
sudo certbot --apache
或者,如果你使用的是Nginx:
sudo certbot --nginx
按照提示操作, Certbot將自動獲取和安裝證書。
首先,創建一個新的systemd服務文件:
sudo nano /etc/systemd/system/certbot.service
將以下內容粘貼到文件中,然后保存并退出:
[Unit]
Description=Let's Encrypt certificate renewal service
Wants=network-online.target
After=network-online.target
[Service]
User=your_username
ExecStart=/usr/bin/certbot renew --quiet
Restart=on-failure
[Install]
WantedBy=multi-user.target
將your_username
替換為運行Certbot的用戶名。
sudo systemctl daemon-reload
sudo systemctl enable certbot.service
sudo systemctl start certbot.service
現在,Let’s Encrypt證書將在到期前自動更新。如果你希望手動檢查更新,可以運行:
sudo certbot renew --quiet
如果證書需要更新,此命令將執行更新操作。