「Lightsail の WordPress を SSL 化する」でLet’s EncryptのSSL証明書を設定してありましたが、証明書の有効期限は90日でそろそろ期限が切れる時期だという通知メールが届いたため、更新を行いました。
証明書の更新については元々参照していたチュートリアルの末尾でもステップ9として以下のように書かれており、ステップ3を繰り返せばよいとのことです。実際にはステップ3~7(7は一部)を行います。
ステップ 9: Let’s Encrypt 証明書を 90 日ごとに更新する
Let’s Encrypt 証明書の有効期間は 90 日間です。証明書は有効期限が切れる 30 日前に更新できます。Let’s Encrypt 証明書を更新するには、取得するために使用した元のコマンドを実行します。このチュートリアルの「Let’s Encrypt の SSL ワイルドカード証明書をリクエストする」セクションのステップを繰り返します。
チュートリアル: Amazon Lightsail の WordPress インスタンスで Let’s Encrypt の SSL 証明書を使用する
目次
ステップ 3: Let’s Encrypt の SSL ワイルドカード証明書をリクエストする
$ DOMAIN=kreyysyy.net $ WILDCARD=*.$DOMAIN $ echo $DOMAIN && echo $WILDCARD kreyysyy.net *.kreyysyy.net
$ sudo certbot -d $DOMAIN -d $WILDCARD --manual --preferred-challenges dns certonly Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator manual, Installer None Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org Cert is due for renewal, auto-renewing... Renewing an existing certificate Performing the following challenges: dns-01 challenge for kreyysyy.net dns-01 challenge for kreyysyy.net - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - NOTE: The IP of this machine will be publicly logged as having requested this certificate. If you're running certbot in manual mode on a machine that is not your server, please ensure you're okay with that. Are you OK with your IP being logged? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: Y - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please deploy a DNS TXT record under the name _acme-challenge.kreyysyy.net with the following value: ◆◆◆DNS TXTレコード用の文字列がここに表示される◆◆◆ Before continuing, verify the record is deployed. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Press Enter to Continue - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please deploy a DNS TXT record under the name _acme-challenge.kreyysyy.net with the following value: ◆◆◆DNS TXTレコード用の文字列がここに表示される◆◆◆ Before continuing, verify the record is deployed. (This must be set up in addition to the previous challenges; do not remove, replace, or undo the previous challenge tasks yet. Note that you might be asked to create multiple distinct TXT records with the same name. This is permitted by DNS standards.) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Press Enter to Continue
ここまで来たら一旦Enterは押さずにステップ4~5へ移り、それが終わってからEnterを押します。
ステップ 4: Lightsail でドメインの DNS ゾーンに TXT レコードを追加する
チュートリアルでは、Lightsailの設定でTXTレコードを追加すればよいと書いてあるのですが、前回、自分の環境では何か見落としてしまっていたのかそれだとうまく行かなかったため、Route53の設定の方でもTXTレコードを追加していました。
今回もLightsailへの追加だけだと新しい証明書が反映されなかったので、仕方なくまたRoute53の方にも設定を行いました。
以下のように、LightsailにもRoute53にも前回登録したTXTレコードが2つあります。これと同様に今回の文字列でTXTレコードを2つ追加します。合計4つになりますが、後で動作確認が終わったら古い2つは削除します。
Lightsail

Route53

ステップ 5: TXT レコードが伝播されたことを確認する
https://mxtoolbox.com/TXTLookup.aspx で、今回新しく設定された文字列が表示されることを確認します。
ステップ 6: Let’s Encrypt の SSL 証明書リクエストを完了する
1. WordPress インスタンスの Lightsail ブラウザベースの SSH セッションで、Enter キーを押し、Let’s Encrypt SSL 証明書のリクエストを続行します。成功すると、次のスクリーンショットに示すようなレスポンスが表示されます。
Waiting for verification... Resetting dropped connection: acme-v02.api.letsencrypt.org Cleaning up challenges IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/kreyysyy.net/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/kreyysyy.net/privkey.pem Your cert will expire on 2020-10-15. To obtain a new or tweaked version of this certificate in the future, simply run certbot again. To non-interactively renew *all* of your certificates, run "certbot renew" - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le
ステップ 7: Apache サーバーディレクトリで Let’s Encrypt の証明書ファイルへのリンクを作成する
リンクは前回すでに作成済みのため、今回は証明書ファイルがちゃんと更新されたかの確認だけ行います。
$ ls -l /opt/bitnami/apache2/conf/server.* lrwxrwxrwx 1 root root 48 Apr 23 03:19 /opt/bitnami/apache2/conf/server.crt -> /etc/letsencrypt/live/kreyysyy.net/fullchain.pem -rw-r--r-- 1 root root 1180 Apr 17 02:50 /opt/bitnami/apache2/conf/server.crt.old -rw-r--r-- 1 root root 985 Apr 17 02:50 /opt/bitnami/apache2/conf/server.csr.old lrwxrwxrwx 1 root root 46 Apr 23 03:19 /opt/bitnami/apache2/conf/server.key -> /etc/letsencrypt/live/kreyysyy.net/privkey.pem -rw------- 1 root root 1675 Apr 17 02:50 /opt/bitnami/apache2/conf/server.key.old $ sudo ls -l /etc/letsencrypt/live/kreyysyy.net/ total 4 lrwxrwxrwx 1 root root 36 Jul 17 01:26 cert.pem -> ../../archive/kreyysyy.net/cert2.pem lrwxrwxrwx 1 root root 37 Jul 17 01:26 chain.pem -> ../../archive/kreyysyy.net/chain2.pem lrwxrwxrwx 1 root root 41 Jul 17 01:26 fullchain.pem -> ../../archive/kreyysyy.net/fullchain2.pem lrwxrwxrwx 1 root root 39 Jul 17 01:26 privkey.pem -> ../../archive/kreyysyy.net/privkey2.pem -rw-r--r-- 1 root root 692 Apr 23 03:09 README $ sudo ls -l /etc/letsencrypt/archive/kreyysyy.net total 32 -rw-r--r-- 1 root root 1923 Apr 23 03:09 cert1.pem -rw-r--r-- 1 root root 1923 Jul 17 01:26 cert2.pem -rw-r--r-- 1 root root 1647 Apr 23 03:09 chain1.pem -rw-r--r-- 1 root root 1647 Jul 17 01:26 chain2.pem -rw-r--r-- 1 root root 3570 Apr 23 03:09 fullchain1.pem -rw-r--r-- 1 root root 3570 Jul 17 01:26 fullchain2.pem -rw------- 1 root root 1704 Apr 23 03:09 privkey1.pem -rw------- 1 root root 1704 Jul 17 01:26 privkey2.pem
/opt/bitnami/apache2/conf/
にあるリンクは前回作成したものがあり、今回もこのままで問題ありません。そのリンク先の/etc/letsencrypt/live/kreyysyy.net/
にあるリンクと、そのリンクの先の/etc/letsencrypt/archive/kreyysyy.net
にある証明書の実体は、末尾2の番号で今回新たに作成されていることが確認できます。
最後に、新しい証明書が読み込まれるように念のためサービスを再起動します。
1. WordPress インスタンスの Lightsail ブラウザベースの SSH セッションで、次のコマンドを入力して基盤となるサービスを停止します。
6. 次のコマンドを入力して、以前に停止した基盤となるサービスを開始します。
$ sudo /opt/bitnami/ctlscript.sh stop Syntax OK /opt/bitnami/apache2/scripts/ctl.sh : httpd stopped /opt/bitnami/php/scripts/ctl.sh : php-fpm stopped /opt/bitnami/mysql/scripts/ctl.sh : mysql stopped $ sudo /opt/bitnami/ctlscript.sh start /opt/bitnami/mysql/scripts/ctl.sh : mysql started at port 3306 /opt/bitnami/php/scripts/ctl.sh : php-fpm started Syntax OK /opt/bitnami/apache2/scripts/ctl.sh : httpd started at port 80