以下の内容はhttps://iww.hateblo.jp/entry/20260205/certbotより取得しました。


certbotで、Let's Encryptの証明書を取得する 4

Debian 13 Trixie では apt でスッと入れてパッと使えるようになって大変便利になった

インストール

apt install certbot

certbotのインストール。 ApacheやNginx用のプラグインもある(python3-certbot-apacheなど)が、別にいらないので入れない

証明書の取得

取得の流れ

certbotコマンドを実行すると、certbot は現在稼働中のWebサーバにこっそり確認用のファイルを置く。
(http://ドメイン名/.well-known/acme-challenge/xxxx)
Let's Encryptの認証局からアクセスできたら証明書が取得でき、所定の場所に秘密鍵と証明書が保存される。
(/etc/letsencrypt/live/ドメイン名/)

なので、とりあえずapacheで HTTPアクセスできるところまでは準備しておく
certbot自体にHTTPサーバをやらせることもできる)

証明書取得コマンド

certbot certonly --webroot -w /var/www/html --cert-name oreore_cert \
    -d aaa.example.com \
    -d bbb.example.com
certonly 証明書を取得するだけ という指定コマンド
Apacheの設定ファイル更新などは人間が自分でやる
--webroot 確認用ファイルを置く場所を自分で指定するモードの指定
-w /var/www/html 確認用ファイルを置く場所
指定箇所の下の .well-known/ にファイルが置かれる
--cert-name oreore_cert 証明書の設定ファイルを置くディレクトリの指定
省略すると最初のドメイン名が丸ごと使われる
-d aaa.example.com 取得したい証明書のドメイン
複数分をひとまとめにするときは複数書く
certbot用設定ファイルの更新(renew用)

証明書を更新したりしたときは apacheの再起動が必要だが、certbot はそんなことを知らないので、設定ファイルで教える

/etc/letsencrypt/renewal/oreore_cert の次のセクションに再起動コマンドを追記する

[renewalparams]
post_hook = systemctl reload apache2

証明書ファイル、秘密鍵ファイル

/etc/letsencrypt/live/oreore_cert/fullchain.pem  ← 証明書
/etc/letsencrypt/live/oreore_cert/privkey.pem    ← 秘密鍵

Apache設定ファイル

だいたいこんな感じにする

<VirtualHost *:443>
    ServerName aaa.example.com
    ServerAdmin kanrisha@example.com

    SSLEngine on
    SSLCertificateFile    /etc/letsencrypt/live/oreore_cert/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/oreore_cert/privkey.pem

    ErrorLog ${APACHE_LOG_DIR}/aaa_error.log
    CustomLog ${APACHE_LOG_DIR}/aaa_access.log combined


    DocumentRoot /var/www/aaa
    <Directory /var/www/aaa>
        Options -Indexes +FollowSymLinks
        AllowOverride AuthConfig FileInfo
        Require all granted
    </Directory>
</VirtualHost>

SSL有効化

本当にApacheインストール直後の場合はいろいろ有効にしないといけないので、次のコマンドを実行する

a2enmod ssl
a2enmod proxy
a2enmod headers
systemctl restart apache2

証明書のメンテナンス

証明書の確認

certbot certificates コマンドで 今 certbotが管理してるドメインとか証明書の一覧が見れる。

# certbot certificates
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Found the following certs:
  Certificate Name: oreore_cert
    Serial Number: 123456789
    Key Type: ECDSA
    Domains: aaa.example.com bbb.example.com
    Expiry Date: 2026-05-03 10:09:25+00:00 (VALID: 89 days)
    Certificate Path: /etc/letsencrypt/live/oreore_cert/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/oreore_cert/privkey.pem

ドメインの追加・変更

ドメインが増えたり減ったりするときは、もういっかい certbot certonly --webroot ・・・ を実行する。
最後に実行したコマンドが記憶されてて、90日以内に再取得がおこなわれる。

証明書の再取得

練習したりする方法。30日切るまでは普通に実行しても再取得はしない

certbot renew                  # 再取得
certbot renew --dry-run        # 再取得したふり
certbot renew --force-renewal  # 強制的に再取得



以上の内容はhttps://iww.hateblo.jp/entry/20260205/certbotより取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14