Let's encrypt standaloneをwebrootに変更

standaloneで取得した場合、一度apacheなりnginxを停止してcertbotを動かさないといけないのが面倒なので、standaloneの設定をwebrootに書き換えます

Problem binding to port 80: Could not bind to IPv4 or IPv6

 書き換えない場合は上記のようにエラーメッセージがでます

 

 

1.設定ファイルの変更

/etc/letsencrypt/renewal/exsample.com.conf
authenticator = standalone
を下記に変更
authenticator = webroot

下記[[webroot_map]]を追加(半角になおしてください)

[[webroot_map]]
exsample.com = /usr/share/nginx/html


2.nginx.confの変更
該当ドメインの「location /」より前に入れると良い

    location ^~ /.well-known/acme-challenge/ {
         root /usr/share/nginx/html;
    }
    location = /.well-known/acme-challenge/ {
         return 404;
    }

変更後は設定を反映
# systemctl reload nginx

 

3.certbotを起動 --no-self-upgradeはcertbotの自動更新を停止
# certbot --no-self-upgrade renew

 

4.root cronにも登録(日曜 3時3分にrenewを実行 有効期限が30日以内で更新)

3 3 * * 0 /usr/bin/certbot renew --no-self-upgrade --post-hook "/usr/bin/systemctl reload nginx"