Let’s EncryptのTLS証明書は2025年9月現在、有効期限が90日です。都度TLS証明書を更新するのは手間なので自動化します。更新はcertbotがやってくれます。
環境はUbuntu Server 24.04 LTSです。
以下で、certbotをインストールしておきます。
sudo apt install certbot
以下にウェブサーバの設定リロードするフックスクリプトを作成して設置します。certbotのフックにはpre、deploy、postの3種類がありますが、ここではdeployで実行します。
cat /etc/letsencrypt/renewal-hooks/deploy/nginx
#!/bin/bash
/usr/bin/systemctl reload nginx.service
初回は以下のコマンドで作成したフックスクリプトを指定して証明書を作成します。
sudo certbot certonly --webroot -w [webサイトのディレクトリ] -d carme-ln.net --deploy-hook=nginx
証明書の自動更新はcertbotをインストールされるとsystemd timerが登録されますので、有効にしておきます。
sudo systemctl enable certbot.timer
sudo systemctl start certbot.timer
sudo systemctl status certbot.timer
● certbot.timer - Run certbot twice daily
Loaded: loaded (/usr/lib/systemd/system/certbot.timer; enabled; preset: enabled)
Active: active (waiting) since Sat 2025-09-06 18:54:01 JST; 5 days ago
Trigger: Fri 2025-09-12 18:37:03 JST; 3h 53min left
Triggers: ● certbot.service
Sep 06 18:54:01 ********** systemd[1]: Started certbot.timer - Run certbot twice daily.
ログなどは/var/log/letsencrypt/letsencrypt.logで確認できます。