Let's Encryptの更新でエラーが出ていたのは公開ディレクトリが変わっていたからだった…


cronでLet's Encryptの自動更新を仕込んでたんですがなぜか更新されない…
ググって似たような症状はあるものの解決しない…

アホみたいな結論だったのでメモしておきます。
私のような人が助かればいいなぁ

結論

最初にSSLを取得したパスと、公開ディレクトリが変わっていた

SSL取得時(とりあえず設定だけしておいた)
/var/www/example.com

実装時
/var/www/example.com/public

後からlaravel導入したからこうなったよね。
letsencryptのconfファイルにパスが記載されているので修正します。※不要な行は掲載してません

/etc/letsencrypt/renewal/example.com.conf
[renewalparams]
webroot_path = /var/www/example.com/public,
[[webroot_map]]
example.com = /var/www/example.com/public

できたら証明書更新して

# certbot renew

Apache再起動して完了

# systemctl restart httpd

詳細知りたい方は続きをどうぞ。

ざっくりと構成

Conoha VPS(このはちゃんかわいい)
CentOS7
Apache2.4
証明書の導入はcertbotクライアント certbot 1.3.0
3サイト載せていてWPが2つ、Laravelが1つ(Laravelだけ更新されなかった…)

試行錯誤の歴史

表示されたエラー

cronで自動更新されてなかったので手動でdryrunかけてみるもエラー

# certbot renew --dry-run --cert-name example.com
IMPORTANT NOTES:
 - The following errors were reported by the server:

   Domain: example.com
   Type:   unauthorized
   Detail: Invalid response from
   https://example.com/.well-known/acme-challenge/xxxxxxxxxxxxx-xxxxxxxxxxxxx
   [192.168.0.1]: "<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n
   <meta charset=\"utf-8\">\n        <meta name=\"viewport\"
   content=\"width=device-w"

   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.

googleさんに色々聞いてみるといろんな説が出てきました。

http通信じゃないとだめだよ説

apacheでhttpはhttpsにリダイレクトかけてたのでリダイレクトをOFFにしてapache再起動
上記エラーでhttpを見に行くも結果変わらず
httpは問題じゃなかった

.well-known/acme-challenge ディレクトリ作っておくんだよ説

/var/www/example.com/public/.well-known/acme-challenge/を作成
中にファイルを置いてブラウザから直接アクセスできることを確認
これでも解決せず
※ただディレクトリは用意しておいて問題ないと思います

wpは更新できてlaravelができない → laravelが悪さしてるんじゃないか説

routingで.well-known/acme-challengeを通すようにしたりしてみましたが変わらず
laravel側のhtaccessのリダイレクトを全部OFFにしても変わらず
そもそも1つ上で試しに設置したファイルにアクセスできてるのでlaravel関係なさそう

そもそもDNS設定できてんのかお前説

サイト表示できてるからできてるわ!

とりあえず詳細表示させてみ

オプションで-vをつけると詳細表示できます
https://free-ssl.jp/command/

-v もしくは --verbose
出力の詳細度を高めます。
このフラグを -vvv のように複数回指定することで、出力の詳細度を更に高めることができます。
(デフォルト: -3)
# certbot renew --dry-run -vvv --cert-name example.com

成功するドメインと比較すると、ここのステータスがpendingになっていた
正常なケースはready

"POST /acme/new-order HTTP/1.1" 201 340
Received response:
HTTP 201
content-length: 340
cache-control: public, max-age=0, no-cache
strict-transport-security: max-age=604800
server: nginx
connection: keep-alive
link: <https://acme-v02.api.letsencrypt.org/directory>;rel="index"
location: https://acme-v02.api.letsencrypt.org/acme/order/00000000/0000000
boulder-requester: 0000000
date: Thu, 23 Jul 2020 11:30:31 GMT
x-frame-options: DENY
content-type: application/json
replay-nonce: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
{
  "status": "pending",
  "expires": "2020-07-30T11:30:31.085174336Z",
  "identifiers": [
    {
      "type": "dns",
      "value": "example.com"
    }
  ],
  "authorizations": [
    "https://acme-v02.api.letsencrypt.org/acme/authz-v3/000000000000"
  ],
  "finalize": "https://acme-v02.api.letsencrypt.org/acme/finalize/0000000/00000000"
}

ただしこのapiやステータスまわりでググっても特に新発見は無し…

更新モードがStandaloneになってるんじゃない?説

Let's EncryptはStandaloneとWebrootモードがあるらしい
アクセスで確認するのがWebrootで設定もWebrootになっていた

/etc/letsencrypt/renewal/example.com.conf
# Options used in the renewal process
[renewalparams]
authenticator = webroot
account = 00000000000000000000
webroot_path = /var/www/example.com,
server = https://acme-v02.api.letsencrypt.org/directory
[[webroot_map]]
example.com = /var/www/example.com

…が、ここで設定ファイルを見て気づく
あれパス違ってね!?
冒頭の結論にあるようにパス修正して完了

解決した瞬間にすごく脱力感に襲われた。
アホすぎて…
あー このはちゃんかわいい