Let’s Encryptの自動更新エラーは設定ファイルを見直す

エラー内容

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/xxx.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert is due for renewal, auto-renewing...
Plugins selected: Authenticator webroot, Installer None
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for xxx.com
Cleaning up challenges
Attempting to renew cert (xxx.com) from /etc/letsencrypt/renewal/xxx.com.conf produced an unexpected error: Missing command line flag or config entry for this setting:
Input the webroot for xxx.com:. Skipping.
All renewal attempts failed. The following certs could not be renewed:
/etc/letsencrypt/live/xxx.com/fullchain.pem (failure)

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

All renewal attempts failed. The following certs could not be renewed:
/etc/letsencrypt/live/xxx.com/fullchain.pem (failure)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

原因

設定ファイルの記述ミス。
※設定ファイルのパスは「/etc/letsencrypt/renewal」。

間違い
[renewalparams]
authenticator = webroot

[webroot_map]
xxx.com = /var/www/html

正しい
[renewalparams]
authenticator = webroot

[[webroot_map]]
xxx.com = /var/www/html

webroot_mapのカッコは二重が正しい。

備考

成功ログ
The following certs were successfully renewed:
/etc/letsencrypt/live/xxx.com/fullchain.pem (success)

失敗ログ
The following certs could not be renewed:
/etc/letsencrypt/live/xxx.com/fullchain.pem (failure)

Basic認証のサイトでLet’s Encryptの自動更新をする方法

対策

特定ディレクトリのBasic認証を外す

#nginx例
location ^~ /.well-known/acme-challenge/ {
satisfy any;
allow all;
}

以下、知識として

「Let’s Encrypt」は、証明書更新時に、ドメインの所有者を確認しています。
具体的な方法としては、更新処理の中で、公開ディレクトリ内の「/.well-known/acme-challenge/」に認証用ファイルを作成して、それを外部から見れたら、ドメインの所有者だと確認しています。

つまりBasic認証がかかっているため、認証用ファイルを外部から確認できず、自動更新できないのです。

認証用ファイル名は毎回異なります。
ディレクトリ単位でBasic認証を外しておきましょう。

Let’s Encryptの自動更新で失敗する原因と対処法【wordpress・cakephp】

自動更新で失敗する原因は主に2つ。
1.認証用ファイルが作成できない
2.認証用ファイルをWEB上で確認できない

対策としては2つ。
1.ルートティレクトリ上に「.well-known/acme-challenge」ディレクトリを作る。
例)
mkdir /var/www/htm/.well-known
mkdir /var/www/htm/.well-known/acme-challenge

2.「.well-known/acme-challenge/xxxxxxxx(認証用ファイル)」をWEB上で公開可能にする。
例)
#nginx.conf
location ^~ /.well-known/acme-challenge/ {
default_type "text/plain";
}

以上

以下、知識として

前提知識として「Let’s Encrypt」は、証明書更新時に、ドメインの所有者を確認しています。
具体的な方法としては、更新処理の中で、公開ディレクトリに認証用ファイルを作成して、それを外部から見れたら、ドメインの所有者だと確認できるという訳です。

「認証用ファイルが作成できない」について

コマンドのオプションでも対応可能。
「.well-known/acme-challenge」ディレクトリが不要になる。
/usr/bin/certbot/certbot-auto renew --webroot -w /var/www/html/

「認証用ファイルをWEB上で確認できない」について

wodpressやcakaphpを利用しているドメインで起きる。
URL書き換えルールが原因(apacheならhtaccess、nginxならnginx.conf)

「.well-known/acme-challenge/xxxxxxxx(認証用ファイル)」をWEBで閲覧できるようにする。
認証用ファイル名は毎回異なる。
ディレクトリ単位で閲覧できるようにする。

エラー出力例

エラー出力例
Attempting to renew cert (xxx.net) from /etc/letsencrypt/renewal/xxx.net.conf produced an unexpected error: Some challenges have failed.. Skipping
IMPORTANT NOTES:
  The following errors were reported by the server:
Domain: xxx.net
Type: unauthorized
Detail: Invalid response from

https://xxx.net/.well-known/acme-challenge/vr-VPSX1sArrECRkqb1iwVAAsCWpaC8xW6_SRCBNb1I

[x.x.x.x]: 403
To fix these errors, please make sure that your domain name was
entered correctly and the DNS A/AAAA record(s) for that domain
contain(s) the right IP address.
  The following errors were reported by the server:

logrotateが動いてない時の対処法【1分で読める】

「logrotateが動いてない!」という時は、cronが止まっている可能性あり

まず原因を特定する

cat /var/lib/logrotate.status

動いている場合の例

logrotate state -- version 2
"/var/log/nginx/error.log" 2019-6-20
"/var/log/yum.log" 2019-6-20
"/var/www/backup/mysql.dmp" 2019-6-21
"/var/log/dracut.log" 2019-6-20

動いてない場合の例

logrotate state -- version 2

こんな時はcronが怪しい。

/etc/init.d/crond status
 crond は停止しています

これで解決

/etc/init.d/crond start