無料SSL Let’s EncryptでWordPressサイトをSSL化する-Ubuntu版

let's encrypt logo

概要

今回は、ubuntu 20.04.2 で無料SSLのLet’s Encryptの「certbot」コマンドを導入してサイトをSSL化する方法を紹介します。

certbotのインストール

certbotをインストールするには、以下のコマンドを投入します。
詳しい 方法はgoogleなどで検索してみてください。

sudo apt install certbot

通常サイトの準備

サイト定義ファイルの作成

まず、httpポート80番で、サイトが見れるようにapacheを設定してください。

apacheの準備ができたら、フォルダ「/etc/apache2/sites-available」に、エディタを使って、
ご使用のドメイン名.conf」という名前のファイルを作ります。
今回の例では当サイトのドメイン名「spankyjpn.com」を使いますので、設定ファイル名は、
spankyjpn.com.conf」となります。
サンプルとして設定例をあげておきます。

<VirtualHost *:80>
   DocumentRoot /home/spanky/《ドキュメントルートフォルダ名》/www
   ServerName 《ドメイン名》
   ServerAlias www.《ドメイン名》 *.《ドメイン名》
   ErrorLog /var/log/apache2/《ドメイン名》_error.log
   CustomLog /var/log/apache2/《ドメイン名》.log combined
   <directory /home/spanky/《ドキュメントルートフォルダ名》/www>
       Options FollowSymLinks Includes ExecCGI
       AllowOverride All
       Require all granted
   </directory>
</VirtualHost>

コンフィグチェックとサイトの起動

設定ファイルを保存し、以下のコマンドを順番に投入してから、apacheを再起動して、サイトがウェブブラウザで見れることを確認してください。

a2ensite spankyjpn.com
apache2ctl configtest
systemctl restart apache2

サイトのSSL化

コマンド投入

次にシェルを開いて、以下のコマンドを投入します。

certbot --apache

インタラクティブに操作

すると、以下のような出力があると思います。ので、SSL化したいサイトのwwwがついたものと、ついていないもの両方を選択します。具体的には、半角の数字を半角スペースで区切って指定します。以下の例では3番の「 spankyjpn.com 」と、4番の「 www.spankyjpn.com 」を選択したところです。

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: spanky-world.com
2: www.spanky-world.com
3: spankyjpn.com
4: www.spankyjpn.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 3 4

番号を入力してエンターキーを押すと処理が走る

以下のような出力が得られると思います。ので次のプロンプトが出るまで待ちます。

Obtaining a new certificate
Performing the following challenges:
http-01 challenge for ncs-ph.com
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/spankyjpn.com-le-ssl.conf
Deploying Certificate to VirtualHost /etc/apache2/sites-available/spankyjpn.com-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/spankyjpn.com-le-ssl.conf
Deploying Certificate to VirtualHost /etc/apache2/sites-available/spankyjpn.com-le-ssl.conf

インタラクティブに操作2

次に、以下のような質問が出ると思います。ここでは「Redirect」を選んでください。指定のドメインへのアクセスは、すべてSSLで処理されるようになります。

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

処理結果

番号「2」を入力してエンターキーを押すと、以下のような表示が出ると思います。
「 Congratulations! 」という表示が出たら成功です。

Redirecting vhost in /etc/apache2/sites-enabled/spankyjpn.com.conf to ssl vhost in /etc/apache2/sites-available/spankyjpn.com-le-ssl.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://spankyjpn.com and
https://www.spankyjpn.com

You should test your configuration at:
https:/ / www.ssllabs.com/ssltest/analyze.html?d=spankyjpn.com
https:/ / www.ssllabs.com/ssltest/analyze.html?d=www.spankyjpn.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/spankyjpn.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/spankyjpn.com/privkey.pem
   Your cert will expire on 2021-10-22. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. 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

root@web05:/etc/apache2/sites-available#
タイトルとURLをコピーしました