Let's encrypt の証明書を無停止で更新する


Let's encryptの証明書の有効期限が90日という衝撃の事実を最近知ったので、今回はその更新方法をまとめておきます。

更新方法

以下のコマンドでOKです。これで、サーバ内で有効期限が近いドメインの証明書が全て更新されます。

なお、私はwget経由でcertbotを取ってきたので以下のようなコマンドになってます。

./certbot-auto renew

certbotがコマンドとして使える場合は以下のようにしてもなるはずです。

sudo certbot renew

これをすればnginxを特に停止させずに更新できました。簡単ですね。

更新した証明書の有効期限を確認する

./certbot-auto certificatesで証明書の有効期限が確認できます。

$ ./certbot-auto certificates
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Found the following certs:
  Certificate Name: xxxxxxxxxx.work
    Domains: xxxxxxxxxx.work
    Expiry Date: 2019-03-01 09:48:21+00:00 (VALID: 41 days)
    Certificate Path: /etc/letsencrypt/live/xxxxxxxxxx.work/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/xxxxxxxxxx.work/privkey.pem

ちなみに、Let's encryptの更新期限が残り20日になると以下のようなメールが届くみたいですね。

Hello,

Your certificate (or certificates) for the names listed below will expire in 19 days (on 01 Feb 19 23:57 +0000). Please make sure to renew your certificate before then, or visitors to your website will encounter errors.

We recommend renewing certificates automatically when they have a third of their
total lifetime left. For Let's Encrypt's current 90-day certificates, that means
renewing 30 days before expiration. See
https://letsencrypt.org/docs/integration-guide/ for details.

xxxxxxxxxx.work

自動更新ではないので注意

自動更新するためにはWebrootプラグインとかが必要みたいですが、私はnginx導入時にそれを導入していなかったので今後も手動で更新していこうと思っています。

もし無停止でWebrootプラグインを導入できて、自動更新できるようなものを知っていればぜひ教えてください。

参考