LoginSignup
0
0

More than 1 year has passed since last update.

certbot letsencrypt cron で 更新

Last updated at Posted at 2022-04-21

何回やってもハマるわ。

webrootモードにしないとnginxを停止しないと更新できなくなる。
まぁcronで止めて、更新後に起動するってのもできるが、
うまく動かない。

ということで webrootモードにする。

一通り ssl の設定が完了したあと


sudo mkdir -p /var/www/html/.well-known
sudo touch /var/www/html/.well-known/test.html

以下を
http と https の設定両方あれば両方に書く。

nginx設定 (defualt.conf)

#適当な ドメインの server 内
location /.well-known {
    root  /var/www/html/;
}

以下のコマンドをやって
2 を選んでリニューアルする(すでにssl設定されていたとしても同様に。)

sudo systemctl restart nginx
sudo certbot certonly --webroot -w /var/www/html/ -d your.com

すでに webrootモードになっているので、
nginxを止めなくても以下のコマンドが成功する。

sudo certbot renew --dry-run

OK

cron設定

7日ごとに certbot を更新してnginxを再起動

#基本はこれ(残り期間が少ない場合のみ更新)
0 1 */7 * * certbot renew --deploy-hook "systemctl restart nginx"

#強制変更したい場合
0 1 */7 * * certbot renew --force-renewal --deploy-hook "systemctl start nginx"

ログを見る

上記やっている中でログを確認したい場合がある。

cronのログを見る

tail /var/log/cron

letsencryptのログを見る

tail /var/log/letsencrypt/letsencrypt.log

エラーになる

適当にやりすぎるとレートリミットにひっかかる。
そうすると7日以上経過しないと処理できなくなるので要注意!
きっちりフォルダにアクセスできるようにしておこう。

IMPORTANT NOTES:
 - The following errors were reported by the server:

   Domain: your.com
   Type:   unauthorized
   Detail: Invalid response from
   http://your.com/.well-known/acme-challenge/kaaaa-aaa
   [2406:da14:48c:3c00:8b46:113:3187:7475]: 404

   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.


ってエラーが出たら
http://your.com/.well-known/acme-challenge
以下に test.html を作ってちゃんと見れるかを確認しよう。
404なのでフォルダにアクセスできないよと言っている。

以上

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0