少し前までは、証明書発行にはお金がかかるものでした。(自己証明書のぞく)
今だとLet’s Encryptなる無料で便利な発行機関があるみたいなので試してみます。
試した環境はEC2のLinux2インスタンスです。
前提知識
証明書の発行時には、申請者がドメインの所有者かを確認する必要があります。
ドメイン認証の一つのやり方に、ウェブサイトに一時的に発行用のトークンを置いておくことで、
たしかに申請者が、そのサイト(ドメイン)の持ち主であるかを確認する、という方法があります。
Let’s Encryptで証明書を発行する場合、certbotというツールを使います。
certbotではウェブサーバ上で自動的にトークンの設置、公開を行い、申請からドメイン認証を自動で行ってくれます。

コンテナ環境利用時の注意点
私の環境ではWebサーバー(wordpress)はコンテナで動いており、ホストの80番ポートはコンテナにフォワードしてしまっています。
certbotはコンテナまでは操作することができないので、80番ポートをに明け渡す必要があります。
そのため、一時的にwordpressをストップし、certbotのstandalone方式で証明書を取得します。
certbotのインストール
# yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# yum install certbot
まず、epelをインストールします。
epelは標準外のパッケージをダウンロードするための拡張リポジトリです。
EC2のLinux 2インスタンスでのインストール方法はAWSの公式に載っています。

epelを有効化することで、epelのパッケージをインストールできるようになります。
次に、epelからcertbotをインストールします。
証明書の発行
# docker stop my_wordpress_wordpress_1
# certbot certonly --standalone -d homatin.com -d www.homatin.com
wordpressのコンテナを停止し、certbotをstandaloneプラグインで実行します。
プラグイン毎の動作の違いは以下の公式を参考にしてください。
実行すると、メールアドレスの確認、利用許諾の確認、ニュースとかキャンペーンを受け取りますか?の質問が聞かれるので、それぞれ答える。
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer None
Enter email address (used for urgent renewal and security notices)
(Enter 'c' to cancel): xxx@yahoo.co.jp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
htt://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
htt://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for homatin.com
http-01 challenge for www.homatin.com
Waiting for verification...
Cleaning up challenges
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/homatin.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/homatin.com/privkey.pem
Your cert will expire on 2020-12-02. 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"
- Your account credentials have been saved in your Certbot
configuration directory at /etc/letsencrypt. You should make a
secure backup of this folder now. This configuration directory will
also contain certificates and private keys obtained by Certbot so
making regular backups of this folder is ideal.
- 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
最後にdockerを起動する。
# docker start my_wordpress_wordpress_1
作成した秘密鍵や証明書は/etc/letsencrypt配下に保存される。
証明書は以下のパスとなる。
/etc/letsencrypt/live/homatin.com/fullchain.pem
ためしに証明書をWindows端末上で、証明書.crtとかで保存して中身を見てみる

無事、発行できた。あとはwordpressのSSLプラグインに放り込めば完了。
コメント