UbuntuサーバーでLetsEncrypt更新した時に、エラーが出てしまった時の話

2021年3月26日

テクノロジー

eyecatch ソフトウェア開発から、サーバー管理まですべて自分で行っている、弓削田です。 CentOSがもはやオワコンなので、先日から、クラウドサーバーOSは、全てubuntuに統一して、 設定をしています。 これまで使っていたCentOSは、かなりハイペースに、ubuntuに置き換えていっています。 その際に、90日で、有効期限が切れてしまう、Let'sEncryptの更新をしようとしたところ、 新しくインストールした、Ubuntuサーバーで、エラーが表示されて、更新ができなかったので、 その時の対応方法についてのメモ書きを残しておきます。

エラーの内容

とりあえず、簡易に証明書をアップデートするコマンドを実行すると、次のようなメッセーが表示されます。 $ certbot renew Saving debug log to /var/log/letsencrypt/letsencrypt.log - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Processing /etc/letsencrypt/renewal/example.com.conf - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Cert not yet due for renewal - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - The following certs are not due for renewal yet: /etc/letsencrypt/live/example.com/fullchain.pem expires on 2021-01-01 (skipped) No renewals were attempted. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ※エラーメッセージは、対象のドメイン名を、example.comに置き換えています。 困りましたね・・・

原因

どうやら、このエラーの原因は、certbotのモードが"standalone"になっていることが原因なのだそうです。 エラーに書かれている Processing /etc/letsencrypt/renewal/example.com.conf の箇所のファイルを開いてみましょう。 # renew_before_expiry = 30 days version = 0.31.0 archive_dir = /etc/letsencrypt/archive/example.com cert = /etc/letsencrypt/live/example.com/cert.pem privkey = /etc/letsencrypt/live/example.com/privkey.pem chain = /etc/letsencrypt/live/example.com/chain.pem fullchain = /etc/letsencrypt/live/example.com/fullchain.pem # Options used in the renewal process [renewalparams] account = **************** authenticator = nginx installer = nginx authenticator = standalone server = https://acme-v02.api.letsencrypt.org/directory ここにかかれている"authenticator"が"standalone"となっているのを"wobroot"にする必要があるようです。

対応方法

とりあえず、次のコードを実行してみます。
certbot certonly --webroot -w /var/www/html/example.com -d example.com
これで、先程のファイルを開いてみると・・・ # renew_before_expiry = 30 days version = 0.31.0 archive_dir = /etc/letsencrypt/archive/example.com cert = /etc/letsencrypt/live/example.com/cert.pem privkey = /etc/letsencrypt/live/example.com/privkey.pem chain = /etc/letsencrypt/live/example.com/chain.pem fullchain = /etc/letsencrypt/live/example.com/fullchain.pem # Options used in the renewal process [renewalparams] account = **************** authenticator = nginx installer = nginx authenticator = webroot server = https://acme-v02.api.letsencrypt.org/directory webroot_path = /var/www/html/example.com, [[webroot_map]] myntinc.com = /var/www/html/example.com 記述の下のほうが書き換わっているのが確認できます。 この状態のまま、証明書更新を実行すると、うまく成功できました。 あ、でも、nginxの再起動をしないと反映できなかったので、apacheも含めてそちらを忘れないようにしましょう。

おまけ

ちなみに、自動更新をするためには、nginxの再起動も含めて、次のコマンドで実行できます。 certbot renew && service nginx -s reload crontabに次を書き込んで置くだけで毎月1日の深夜3時に自動的に更新してくれるようになりますよ。 00 03 01 * * certbot renew && service nginx -s reload お試しあれ!

人気の投稿

このブログを検索

ごあいさつ

このWebサイトは、独自思考で我が道を行くユゲタの少し尖った思考のTechブログです。 毎日興味がどんどん切り替わるので、テーマはマルチになっています。 もしかしたらアイデアに困っている人の助けになるかもしれません。

ブログ アーカイブ