Bitnami WordPress HTTPS化+リダイレクト関連簡単設定

AWS
スポンサーリンク

こんにちは、たらこです。
先日、AWS Lightsail Bitnami WordPressで
wwwあり→wwwなし(www to non-www)リダイレクト設定の記事を書いたんですが、
なんとHTTPS化(証明書作成・自動更新)の設定とともに、簡単に設定できる方法があったので、
備忘録として記載していきます。

こんな人に読んでほしい

  • これからAWS Lightsail Bitnami WordPressでブログ構築しようとしている方
  • HTTPS化、リダイレクト設定等の設定に躓いている方

Bitnami WordPressのHTTPS化はコマンド一発でOK

AWSのBitnami WordPressイメージにはHTTPS化 (証明書作成・自動更新設定) が
簡単にできるように、特別なツールが用意されています。
まずは、ツールをダウンロードします。(プリインストールされている場合もあります。)

wget -O bncert-linux-x64.run https://downloads.bitnami.com/files/bncert/latest/bncert-linux-x64.run
sudo mkdir /opt/bitnami/bncert
sudo mv bncert-linux-x64.run /opt/bitnami/bncert/
sudo chmod +x /opt/bitnami/bncert/bncert-linux-x64.run
sudo ln -s /opt/bitnami/bncert/bncert-linux-x64.run /opt/bitnami/bncert-tool

上記でツールのインストールが完了です。

起動は下記コマンド一発でOKです。

sudo /opt/bitnami/bncert-tool

bncert-toolはリダイレクト設定も併せてやってくれる!

さて、ここからが本題です。
上記のbncert-toolはさらに追加設定の機能を持っています。
証明書関連も含め実施できる設定は下記になります。

  • Let’s Encryptionでの証明書作成
  • 1か月ごとの証明書の自動更新設定
  • サーバ名を入力したドメインに変更
  • HTTP→HTTPSリダイレクト設定
  • wwwあり→wwwなし/wwwなし→wwwありリダイレクト設定

そうなんです。リダイレクト設定も指定すれば一緒にやってくれるんです。
なんて便利なの。

設定方法

まずは、上記のツールダウンロード方法で、ツールをダウンロードします。
その後下記コマンドを実行します。

sudo /opt/bitnami/bncert-tool

その後、下記のようにドメインを聞かれますので入力してEnterを押します。

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

The web server name will be configured as the first provided domain name.

If you provide a non-www domain (e.g. example.com) but not its www subdomain
(e.g. www.example.com), it will be added automatically, and viceversa.

Domain list []:

その後、下記のような設定をしますよ、というアナウンス表示が出ます。

----------------------------------------------------------------------------
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:
/opt/bitnami/letsencrypt/certificates/cyber-x-cyber.net.crt
3. Disable existing Let's Encrypt cron jobs configured with the tool
4. Configure a cron job to automatically renew the certificates each month
5. Configure web server name to: cyber-x-cyber.net
6. Enable HTTP to HTTPS redirection (example: redirect https://cyber-x-cyber.net
to https://cyber-x-cyber.net)
7. Enable non-www to www redirection (example: redirect cyber-x-cyber.net to
www.cyber-x-cyber.net)
8. Start web server once all changes have been performed

You can modify the list of changes to perform if you select 'No'

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

リダイレクト設定については6,7番で記載されていますが、初期状態だと下記が設定されます。

  • HTTP→HTTPSリダイレクト
  • wwwなし→wwwありリダイレクト

もし、HTTP→HTTPSリダイレクトはしたくない、wwwあり→wwwなしリダイレクトにしたい、
どちらも設定したくない、という場合は下記のようにして設定変更できます。

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

上記が出てきたら、まず「n」を入力してEnterを押します。
すると下記メッセージが表示されます。

Do you agree to these changes? [Y/n]: n (nを押してEnter)


----------------------------------------------------------------------------
Additional configuration

Please select the list of changes you wish to perform on your Bitnami
installation.



Enable HTTP to HTTPS redirection [Y/n]:

HTTP→HTTPSリダイレクト設定をしたければ「y」、したくなければ「n」を入力。

次に下記のようなメッセージが表示されます。

Enable non-www to www redirection [Y/n]:

wwwなし→wwwありリダイレクトの設定をしたければ「y」、したくなければ「n」を入力。

最後に下記のようなメッセージが表示されます。

Enable www to non-www redirection [y/N]:

wwwあり→wwwなしリダイレクトの設定をしたければ「y」、したくなければ「n」を入力。

※wwwリダイレクトの設定はどちらか一方のみを設定することが可能です(「y」は1個だけ)。
※どちらも設定したくない場合は両方に「n」を入力してください。

上記が完了すると、もう一度これから実施する設定のアナウンスが表示されます。

(下記ように設定変更した場合の表示)
(Enable HTTP to HTTPS redirection [Y/n]: y)
(Enable non-www to www redirection [Y/n]: n)
(Enable www to non-www redirection [y/N]: y)
----------------------------------------------------------------------------
Changes to perform

The following changes will be performed to your Bitnami installation:

1. Stop web server
2. Configure web server to use an existing Let's Encrypt certificate and renew:
/opt/bitnami/letsencrypt/certificates/cyber-x-cyber.net.crt
3. Disable existing Let's Encrypt cron jobs configured with the tool
4. Configure a cron job to automatically renew the certificates each month
5. Configure web server name to: cyber-x-cyber.net
6. Enable HTTP to HTTPS redirection (example: redirect https://cyber-x-cyber.net
to https://cyber-x-cyber.net)
7. Enable www to non-www redirection (example: redirect www.cyber-x-cyber.net to
cyber-x-cyber.net)
8. Start web server once all changes have been performed

You can modify the list of changes to perform if you select 'No'

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

上記で問題なければ「y」を入力して設定を開始してください。

下記メッセージが表示され、メールアドレスの入力を求められます。

----------------------------------------------------------------------------
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: cyber-x-cyber.net www.cyber-x-cyber.net

Server name: cyber-x-cyber.net

E-mail address []:

自身のメールアドレスを入力してEnterを押します。

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

Let’s Encryptへの登録の同意を聞かれますので、「y」を入力してEnterを押します。


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

Successの表示が出れば完了です。
ね、とっても簡単でしょう?

まとめ

今回はAWS Lightsail Bitnami WordPressでHTTPS化と併せて、
各種リダイレクト設定をする方法をまとめました。
とっても便利なので、ぜひ利用してみてください。

では、よいサイバーライフを!

コメント

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