在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 如果证书需要更新,此命令将执行更新操作。