AWS Lightsail の Let’s Encrypt の SSL証明書を更新する方法:

下記を参考にしました。

https://qiita.com/tomokei5634/items/fdccda2aa9c83d5655f5

2024/3/7追記

%sudo /opt/bitnami/bncert-tool

  • Let’s Encrypt on AWS bitnami (SSL証明書の更新)
    1. 前提
      • Let’s Encryptの証明書期限が90日間あり、基本的に期限30日前に自動更新されるが、更新ツールがうまく作動せず、期限が30日未満(実績12~19日前)になると、証明書発行時に登録したメールアドレスにお知らせが飛んでくる
      • Subject: Let's Encrypt certificate expiration notice for domain "simisin.net"
        Body: Your certificate (or certificates) for the names listed below will expire in 19 days (on 2024-03-22). Please make sure to renew your certificate before then, or visitors to your web site will encounter errors.
    2. 更新前にやること
      • Cloudflare DNS records
        • SSL証明書更新対象のドメイン及びサブドメインのA (ipv4)及びAAAA(ipv6)のProxy statusを一時的にoff (ProxiedからDNS onlyへ変更)にする
          • Proxiedだと更新ツールがIPを正常取得できずinstallでコケる
            • An error occurred renewing certificates with Let's Encrypt:
              2024/03/07 01:58:45 error: one or more domains had a problem:
              [simisin.net] acme: error: 403 :: urn:ietf:params:acme:error:unauthorized ::
              Cannot negotiate ALPN protocol "acme-tls/1" for tls-alpn-01 challenge
      • bitnamiでbncert-toolを実行する
        • 設定
          • Domain list []:
            • サブドメインも並列で記載する(例: domain.com blog.domain.com sub.domain.com など)
          • Warning: A certificate for the list of domains you entered already exists. It will be used instead of generating a new one.
            Press [Enter] to continue:
            • 既存の証明書を上書きして続行する
          • Enable HTTP to HTTPS redirection [Y/n]: Y
          • E-mail address []:
            • 証明書期限切れ通知が来た連絡用メールアドレスを入力 (contact@~など)
      • apacheのconfigが正しい証明書を参照しているか確認
        • ミスってると下記のエラーログがでる
          • $sudo tail -f /opt/bitnami/apache2/logs/error_log
            • AH01909: simisin.net:443:0 server certificate does NOT include an ID which matches the server name
          • $sudo vi /opt/bitnami/apache2/conf/vhosts/simisin-https-vhost.conf
            • SSLCertidicateFile "/opt/bitnami/apache2/conf/simisin.net.crt"
            • SSLCertidicateFile "/opt/bitnami/apache2/conf/simisin.net.key"
      • 作業が終わったら、Cloudflare Proxy = on (Proxied)へ戻して終わり
    3. 自動更新の確認
      • crontabで自動更新を複数ドメイン対応に変更する #デフォルトだとなってない
        • $sudo crontab -e -u bitnami
          • 19 6 * * * sudo /opt/bitnami/letsencrypt/lego --path /opt/bitnami/letsencrypt --email="contact@simisin.net" --http --http-timeout 30 --http.webroot /opt/bitnami/apps/letsencrypt --domains=simisin.net --domains="*.simisin.net" --domains=s-shimizu.com --user-agent bitnami-bncert/2.0.1 renew && sudo /opt/bitnami/apache/bin/httpd -f /opt/bitnami/apache/conf/httpd.conf -k graceful # bncert-autorenew
          • $ sudo cat /var/spool/cron/crontabs/bitnami #crontab置き場所を直参照
      • 上記は毎回更新の度に上書きされるのはしんどいので.shにする
        • %sudo vi /home/bitnami/cert-renew.sh
          • !/bin/bash
            sudo /opt/bitnami/letsencrypt/lego --path /opt/bitnami/letsencrypt --email="contact@simisin.net" --http --http-timeout 30 --http.webroot /opt/bitnami/apps/letsencrypt --domains="simisin.net" --domains="blog.simisin.net" --domains="s-shimizu.com" --user-agent bitnami-bncert/2.0.1 renew >> /var/log/cert-renew.log 2>&1 && sudo sleep 30 && sudo /opt/bitnami/ctlscript.sh restart apache
          • %sudo chmod +x /opt/bitnami/cert-renew.sh
          • %sudo chown bitnami /opt/bitnami/cert-renew.sh
          • %sudo chgrp bitnami /opt/bitnami/cert-renew.sh
        • %sudo crontab -e
          • 0 0 1 * * /home/bitnami/cert-renew.sh

IPv6チェックSkip

  • Let’s Encryptの90days毎の自動更新ですが、IPv6対応(validation & DNS checkをスキップ)する方法があったのでメモ
    • $sudo /opt/bitnami/bncert-tool --perform_public_ip_validation 0 --perform_dns_validation 0
    • 参考

更新切れの確認方法

  • %sudo openssl x509 -noout -dates -in /opt/bitnami/apache2/conf/domain.net.crt
    notBefore=Dec 16 16:05:37 2024 GMT
    notAfter=Mar 16 16:05:36 2025 GMT →切れている
  • %openssl s_client -connect domain.net:443 < /dev/null 2> /dev/null | openssl x509 -text | grep "Not"
    Not Before: Dec 16 16:05:37 2024 GMT
    Not After : Mar 16 16:05:36 2025 GMT →切れている

By admin

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です