Amazon LightsailのWordPressサイトSSLを設定・更新する方法

Amazon LightsailでWordPressを運用し始めて数ヶ月。一度設定してしまえばブログを書くだけでいいんだけど、SSLの更新だけは手動でする必要がある。

手順はとても簡単でAmazon公式サイトにある以下の記事に従うだけ。

Tutorial: Using Let’s Encrypt SSL certificates with your WordPress instance in Amazon Lightsail

ここでは公式サイトを見なくてもできるように必要なところだけをまとめておく。

SSL更新手順

1. AWS Lightsailコンソールにログインし、ターミナルを立ち上げる

2. DOMAIN と WILDCARD を vi エディタなどで .bashrc ファイルの最後に記入し、環境変数として設定。次回以降はスキップすればいい。

# DOMAIN and WILDCARD configuration
DOMAIN=takarocks.com
WILDCARD=*.$DOMAIN

3. 以下の certbot コマンドを実行 (公式ガイドの Step 3)

sudo certbot -d $DOMAIN -d $WILDCARD --manual --preferred-challenges dns certonly

4. IPアドレス記録のメッセージが出るので Y を選択する。Nを選択するとエラーとなりここで手順がストップする。

Last login: Mon May 24 14:23:27 2021 from xxx.xxx.xxx.xxx
bitnami@ip-xxx-xxx-xxx-xxx:~$ 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
Cert is due for renewal, auto-renewing...
Renewing an existing certificate
Performing the following challenges:
dns-01 challenge for takarocks.com
dns-01 challenge for takarocks.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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: 

5. ちなみにセキュリティ期限に余裕がある場合には更新の必要がないため以下のメッセージが出る。更新したい場合には 2 を入力することで進めることができる。

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator manual, Installer None
Cert not yet due for renewal

You have an existing certificate that has exactly the same domains or certificate name you requested and isn't close to expiry.
(ref: /etc/letsencrypt/renewal/takarocks.com.conf)

What would you like to do?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: Keep the existing certificate for now
2: Renew & replace the cert (limit ~5 per 7 days)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 

6. メッセージに従い TXT レコードをLightsailのDNS Zoneに登録する

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name
_acme-challenge.takarocks.com with the following value:

_abcdefghijklmnopqrstuABCDEFGHIKLMNOPQRSTU

Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue

7. mxtoolboxなどTXTレコードが参照できるサービスを使って登録した内容を確認する

https://mxtoolbox.com/SuperTool.aspx

8. コンソールに戻り、Enterを押して継続する

9. 手順3と同じ内容のメッセージが出てくる。これは、2つめのTXT登録が促されているので、手順5と6をもう一度繰り返し、2レコード確認できたらEnterを押して続行する。

10. 設定が正しく認識されて成功すると以下の内容が表示される

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/takarocks.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/takarocks.com/privkey.pem
   Your cert will expire on 2021-08-22. 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

10. 以下のスクリプトを使ってWordPressサービスの再起動

sudo /opt/bitnami/ctlscript.sh stop
sudo /opt/bitnami/ctlscript.sh start

11. TXTレコードは残していても問題ないが、SSL更新のための正しいドメインかどうかの確認のためのもので今後は不要なので、2つのTXTエントリーはここで消しておく。

12. これで問題なくSSLの更新ができているが、最後念の為の確認のためサイトのSSL情報をブラウザから確認してみると、期間が90日延長されたことがわかる。

次の更新はハロウィン前だね

コメントを残す

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