MENU
やすひら
やすひらと申します。
長靴を履いたタヌキ(ITエンジニア)です。
モノ作りの楽しさを発信中。
X(旧Twitter)のフォローもお願いします。

[WordPress]SSL証明書の設定方法

WordPressの通信をSSL化する方法を紹介します。

やすひら

SSL化する方法を紹介します

この記事でわかること
  • SSLとは
  • SSL化する方法
目次

SSLとは

SSLとは、Secure Sockets Layerの略で、通信の暗号化技術です。
ブログでSSLを使用することで、ブラウザ-Webサーバー間の通信が暗号化され、セキュアに通信することが可能となります。
SSL化を行う際には、認証局(CA)からSSLサーバー証明書を発行してもらい、サーバーが本物であることを証明します。

SSL化しているメリットは、通信が暗号化されて安心してWebページが閲覧出きることと、ブログ運営の信頼性を向上することです。

cerbotによるSSL証明書の取得

SSL証明書の取得先として、Let’s Encrypt認証局から発行することが可能です。
Let’s EncryptからSSL証明書を取得は無料であることが大きなメリットです。

apacheの設定

apacheの設定ファイルにドメインを設定します。
Ubuntuの場合は、以下の設定ファイルを設定します。

コマンドライン

sudo vi /etc/apache2/sites-available/000-default.conf

設定ファイル

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        ServerName yasuhira-blog.com

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

apacheの設定ファイルにドメインを設定します。

apacheの再起動

apacheを再起動します。

コマンドライン

sudo service apache2 restart

apacheを再起動して設定ファイルを読み込みます。

cerbotのインストール

cerbotをインストールします。

コマンドライン

sudo apt install certbot python3-certbot-apache

aptコマンドでcerebotをインストールします。

cerbotでSSL証明書を発行

cerbotを実行して、SSL証明書を取得します。

コマンド実行例

$ sudo certbot --apache -d yasuhira-blog.com

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): [メールアドレス]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.3-September-21-2022.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: N
Account registered.
Requesting a certificate for yasuhira-blog.com

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/yasuhira-blog.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/yasuhira-blog.com/privkey.pem
This certificate expires on 2023-05-23.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

Deploying certificate
Successfully deployed certificate for yasuhira-blog.com to /etc/apache2/sites-available/000-default-le-ssl.conf
Congratulations! You have successfully enabled HTTPS on https://yasuhira-blog.com

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

crebotでSSL証明書を取得します。

SSL化の確認

SSL証明書が発行できたら、WebページがSSL化されているか確認します。
ブラウザのURL入力部分に、以下のURLを入力して確認します。

URL

https://yasuhira-blog.com

Webページが正常に閲覧できていれば、SSL化できています。

SSL証明書の更新

Let’s EncryptのSSL証明書の有効期限は3ヶ月のため、定期的に更新する必要があります。
cerbotでは自動更新機能があり、定期的に更新しています。
以下で動作確認することができます。

コマンド実行例

$ sudo systemctl status certbot.timer

● certbot.timer - Run certbot twice daily
     Loaded: loaded (/lib/systemd/system/certbot.timer; enabled; vendor preset:>
     Active: active (waiting) since Wed 2023-02-22 23:44:08 JST; 19min ago
    Trigger: Thu 2023-02-23 05:48:29 JST; 5h 44min left
   Triggers: ● certbot.service

Feb 22 23:44:08 machine000 systemd[1]: Started Run certbot twice daily.

SSL証明書を定期的に自動更新できているか確認します。

まとめ

SSL化の方法について紹介いたしました。

SSL化の方法は
  • apacheを設定
  • cerbotでSSL証明書を発行

SSL化されたWebページを閲覧できるようになり、セキュアなWebページを提供できます。

  • URLをコピーしました!
目次