見出し画像

Let'sEncryptの更新に失敗した話

どうもこんばんは。

SSL証明書の更新に苦戦しました。
経緯を載せておきます。
Let'sEncyptとは?の説明は多くの記事があるので省略します。

エラー発生

証明書はcronで自動更新しておくように紹介されることが多く、
私もその例に漏れずシェルを作成して自動更新をするつもりでした。
しかし、ログを確認したところエラーが出ていました。

シェルに問題はなさそうだったので、
手動更新を実行・・・もエラーに。

# certbot renew

Saving debug log to /var/log/letsencrypt/letsencrypt.log

-------------------------------------------------------------------------------
Processing /etc/letsencrypt/renewal/example.com.conf
-------------------------------------------------------------------------------
Cert is due for renewal, auto-renewing...
Plugins selected: Authenticator webroot, Installer None
Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for example.com
Cleaning up challenges
Encountered exception during recovery
[Errno 2] No such file or directory: '/opt/bitnami/apps/wordpress/htdocs/.well-known/acme-challenge/-uMl_J4Vbq-R0VmxRihUc7OWt085tXXOy611LiohVes'
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/certbot/error_handler.py", line 103, in _call_registered
  self.funcs[-1]()
File "/usr/lib/python2.7/dist-packages/certbot/auth_handler.py", line 308, in _cleanup_challenges
  self.auth.cleanup(achalls)
File "/usr/lib/python2.7/dist-packages/certbot/plugins/webroot.py", line 219, in cleanup
  os.remove(validation_path)
OSError: [Errno 2] No such file or directory: '/opt/bitnami/apps/wordpress/htdocs/.well-known/acme-challenge/-uMl_J4Vbq-R0VmxRihUc7OWt085tXXOy611LiohVes'
Attempting to renew cert (example.com) from /etc/letsencrypt/renewal/example.com.conf produced an unexpected error: [Errno 2] No such file or directory
: '/opt/bitnami/apps/wordpress/htdocs'. Skipping.
All renewal attempts failed. The following certs could not be renewed:
/etc/letsencrypt/live/example.com/fullchain.pem (failure)

-------------------------------------------------------------------------------

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)

原因はおそらく以前使用していたwordpressの影響みたいです。

confファイルを修正

ログを見た感じですとpythonファイルにもエラーが出ていますが、
対処法として多く出てくるconfファイルを修正することに。

# vi /etc/letsencrypt/renewal/example.com.conf
以下の状態になっていました。

# renew_before_expiry = 30 days
version = 0.23.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]
authenticator = webroot
installer = None
account = 3bccead0a9966a0069aaf7496e28b07a
webroot_path = /opt/bitnami/apps/wordpress/htdocs,
[[webroot_map]]
example.com = /opt/bitnami/apps/wordpress/htdocs
末尾3行分を以下のように修正(webroot_pathとexample.comの部分)

webroot_path = /var/www/html,
[[webroot_map]]
example.com = /var/www/html

ドキュメントルートを記載しました。
webroot_pathの末尾の","は元からあったので残してあります。

証明書の更新をしてみよう

ファイルの修正が完了したら証明書を更新してみましょう。
私の場合、証明書更新のシェルを実行しました。
もちろん、certbot renewでもOK。
今度はエラーになることなく更新されました。
ログには以下のようなことが書いてありました。

-------------------------------------------------------------------------------
new certificate deployed without reload, fullchain is
/etc/letsencrypt/live/example.com/fullchain.pem
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------

Congratulations, all renewals succeeded. The following certs have been renewed:
 /etc/letsencrypt/live/example.com/fullchain.pem (success)
-------------------------------------------------------------------------------

ちゃんとsuccessになっている!

Apache再起動

更新されたことを確認するためにブラウザを開くのですが、
どうも有効期限が変わっていませんでした。
が、Apacheを再起動したら解決しました。

# service apache2 restart

この記事が気に入ったらサポートをしてみませんか?