LightsailのWordPressマルチサイトでHTTPSを有効化してみた

AWS
AWS
この記事は約9分で読めます。

ドメインを使用してWordPressにアクセスできるようになったため、今度はHTTPSを有効化した上、HTTPでの接続をHTTPSにリダイレクトする設定をします。

この記事で行う作業は以下のとおりです。

  • インスタンスにSSH接続
  • bncertツールを使用し、Let’s Encrypt 認証局からSSL/TLS証明書を作成
  • プラグインにより HTTP -> HTTPS のリダイレクト設定

作業に入る前に、簡単に用語について説明します。

bncertツールとは

Bitnamiが提供するHTTPSの設定ツールであり、bncertツールを使用することで簡単にHTTPSの設定ができます。

Learn about the Bitnami HTTPS Configuration Tool

Let’s Encryptとは

無料で簡単にHTTPSを有効にするために必要な証明書を発行できる認証局です。

Let's Encrypt について - Let's Encrypt - フリーな SSL/TLS 証明書
Let’s Encrypt は、公共の利益のために運営されている、フリーで自動化されたオープンな認証局 (certificate authority; CA) です。 インターネット・セキュリティ・研究グループ (Internet Security Research Group; ISRG) がサービスを提...

bncertツールを使用し、HTTPSを有効にする

ブラウザからインスタンスにSSH接続し、以下のコマンドを実行すると、対話式で進んでいきます。

$ sudo /opt/bitnami/bncert-tool
// マルチサイトの場合はリダイレクトの設定ができないようです
Warning: Custom redirections are not supported in the WordPress Multisite 
packaged by Bitnami. This tool will not be able to enable/disable redirections.
Press [Enter] to continue:
----------------------------------------------------------------------------
Welcome to the Bitnami HTTPS Configuration tool.

----------------------------------------------------------------------------
Domains

Please provide a valid space-separated list of domains for which you wish to 
configure your web server.
// 証明書を発行したいドメイン名を入力します。
Domain list []: fun-every-day.com

The following domains were not included: www.fun-every-day.com. Do you want to add them?
 [Y/n]: n

----------------------------------------------------------------------------
Changes to perform

The following changes will be performed to your Bitnami installation:

1. Stop web server
2. Configure web server to use a free Let's Encrypt certificate for the domains: 
fun-every-day.com
// 証明書の自動更新をしてくれます。
3. Configure a cron job to automatically renew the certificate each month
4. Configure web server name to: fun-every-day.com
5. Start web server once all changes have been performed

Do you agree to these changes? [Y/n]: 

----------------------------------------------------------------------------
Create a free HTTPS certificate with Let's Encrypt

Please provide a valid e-mail address for which to associate your Let's Encrypt 
certificate.

Domain list: fun-every-day.com

Server name: fun-every-day.com

E-mail address []: xxx@xxx.xx

The Let's Encrypt Subscriber Agreement can be found at:

https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf

Do you agree to the Let's Encrypt Subscriber Agreement? [Y/n]: 


----------------------------------------------------------------------------
Performing changes to your installation

The Bitnami HTTPS Configuration Tool will perform any necessary actions to your 
Bitnami installation. This may take some time, please be patient.

----------------------------------------------------------------------------
Success

The Bitnami HTTPS Configuration Tool succeeded in modifying your installation.

The configuration report is shown below.

Backup files:
* /opt/bitnami/apache/conf/httpd.conf.back.202204131156
* /opt/bitnami/apache/conf/bitnami/bitnami.conf.back.202204131156
* /opt/bitnami/apache/conf/bitnami/bitnami-ssl.conf.back.202204131156
* /opt/bitnami/apache/conf/vhosts/wordpress-https-vhost.conf.back.202204131156
* /opt/bitnami/apache/conf/vhosts/wordpress-vhost.conf.back.202204131156

Find more details in the log file:

/tmp/bncert-202204131156.log

If you find any issues, please check Bitnami Support forums at:

GitHub - bitnami/vms: Bitnami VMs
Bitnami VMs. Contribute to bitnami/vms development by creating an account on GitHub.
Press [Enter] to continue:

なお、上記を成功させるには、HTTP、HTTPSポートを開く必要があります(もしかしたらHTTPSだけでもいいかも)。

私はファイアウォールで自宅のグローバルIPに制限していたため、途中で以下のエラーメッセージが発生しました。

Could not obtain certificates:
error: one or more domains had a problem:
[fun-every-day.com] acme: error: 400 :: urn:ietf:params:acme:error:connection :: 
Timeout during connect (likely firewall problem)

HTTPSにリダイレクトさせる

以下チュートリアルの「ステップ 8: Really Simple SSL プラグインを使用して SSL 証明書を WordPress サイトに統合する」の手順に従います。なお、マルチサイトでないWordPressの場合、上記のbncertツールだけでリダイレクトが設定できるはずなので、このセクションの手順は必要ありません。

チュートリアル: Amazon Lightsail の WordPress インスタンスで Let's Encrypt の SSL 証明書を使用する | Lightsail ドキュメント

プラグインはwp-config.php および htaccess.conf ファイルに書き込むとチュートリアルに記載されているため、各ファイルの権限を設定します(ただし、ファイルに自動的に書き込む様子は見受けられなかったため、不要かもしれません。)。

// DebianとUbuntuで実行するコマンドが異なるため確認
$ cat /proc/version 
Linux version 4.19.0-20-cloud-amd64 (debian-kernel@lists.debian.org) (gcc version 8.3.0 (Debian 8.3.0-
6)) #1 SMP Debian 4.19.235-1 (2022-03-17)

$ sudo chmod 666 /opt/bitnami/wordpress/wp-config.php && sudo chmod 666 /opt/bitnami/apache/conf/vhosts/htaccess/wordpress-htaccess.conf

Really Simple SSL プラグインをインストールします。

インストール後はプラグインを有効化し、サイトネットワークでSSLを有効化します。

以上の設定により、HTTPでWordPressにアクセスすると、自動的にHTTPSにリダイレクトされるようになりました。Really Simple SSL プラグインはその他の機能もありますが、今回はリダイレクト設定のみ扱いました。

タイトルとURLをコピーしました