Apitore blog

Apitoreを運営していた元起業家のブログ

Let's Encryptでrenewが失敗するときのTips

はじめに

ApitoreのSSL証明書はLet's Encryptを使っています。そちらについてはQiitaやブログで色々とTipsを紹介してきました。うまく動いていたのですが、直近に行われた証明書のアップデートが失敗するようになりました。今回はその対策のTipsです。

エラー内容

いつから失敗するようになったのか定かではありませんが、以下のエラーメッセージが出るようになりました。

The following certs are not due for renewal yet:
All renewal attempts failed. The following certs could not be renewed:
  /etc/letsencrypt/live/example.com/fullchain.pem (failure)
1 renew failure(s), 0 parse failure(s)
IMPORTANT NOTES:
 - The following errors were reported by the server:
   Domain: example.com
   Type:   unauthorized
   Detail: Invalid response from
   http://example.com/.well-known/acme-challenge/hogehogehogehogehogehoge:
   "{"timestamp":1493613447065,"status":404,"error":"Not
   Found","message":"No message
   available","path":"/.well-known/acme-challenge"
   To fix these errors, please make sure that your domain name was
   entered correctly and the DNS A record(s) for that domain
   contain(s) the right IP address.

どうやらhttp://example.com/.well-known/acme-challenge/にアクセスできないようです。たしかに、Apitoreではnginxを使っていますが、そこのURLは開けていません。Let's EncryptはSSL証明書を発行するにあたり、発行元の確認で以上のURLにアクセスして簡易的な認証を行うようです。(いつからこのような仕様になったのでしょうか?はじめから?)確かに、その方がセキュアです。

対策

こちらで紹介するように、ApitoreではLet's EncryptをWebrootモードで実行しています。Webrootは/var/www/example.com/としています。そこで、2つの施策を打ちます。

1. フォルダ作成

webrootにフォルダ/var/www/example.com/.well-known/acme-challenge/を作成します。

2. nginxの設定変更

nginxの設定も変更します。

server {
  // 中略
  location ^~ /.well-known/acme-challenge/ {
    default_type "text/plain";
    root         /var/www/example.com;
  }
  // 中略
}

おわりに

以上で対策は完了です。これでcertbot-auto renewの認証がとおりました。certbotの自動更新は切っていたのですが、あらためてバージョンを更新してみました。0.8.1から0.13.0?だったかな?結構アップデートされていました。なにはともあれ、これでまたSSL証明書は放置できるはず。

参考