複数のサブドメインを持っている場合は、SSL証明書をそれぞれに取得することができますが、メンテナンス上では、やや面倒です。この問題を解決するために、“Let‘s encrypt”でワイルドカード証明書を取得し、インストールすれば解決することができます。
ここではまだ、LinuxサーバにSSL証明書をインストールする方法のみを紹介します。
1 “Cerbot”クライアントと“modssl”モジュールのインストール
まず、“Cerbot”クライアントと“modssl”モジュールがインストールされているかどうかを確認します。まだインストールされていない場合は、当サイト「Let’s encrypt が発行する SSL 証明書を取得する」の内容を参考にしてください。
2 ワイルドカード付きの“Let‘s encrypt”SSL証明書の取得
取得方法は以下の通りです。
[root@usite ~]# certbot certonly --manual \
--server https://acme-v02.api.letsencrypt.org/directory \
--preferred-challenges dns \
-d *.DomainName -d DomainName \
-m UMail@Address \
--agree-tos \
--manual-public-ip-logging-ok ← ワイルドカード付きのSSL証明書の取得
事例:
DomainName:usite.com ← ドメイン名
UMail@Address:サイト管理用メアド
Use of --manual-public-ip-logging-ok is deprecated.
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator manual, Installer None
Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org
Use of --manual-public-ip-logging-ok is deprecated.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
You have an existing certificate that contains a portion of the domains you
requested (ref: /etc/letsencrypt/renewal/usite.com.conf)
It contains these names: usite.com
You requested these names for the new certificate: *.usite.com, usite.com.
Do you want to expand and replace this existing certificate with the new
certificate?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(E)xpand/(C)ancel: E ← SSL証明書の入替え
Renewing an existing certificate for *.usite.com and usite.com
Performing the following challenges:
dns-01 challenge for usite.com
dns-01 challenge for usite.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name
_acme-challenge.usite.com with the following value:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx-dXXxxxXXxxoio
Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue ← 「Enter」キーを押す前に、上記のTXT情報をDNSサーバに登録
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name
_acme-challenge.usite.com with the following value:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx-aXXxxxXXxx4Bs
Before continuing, verify the record is deployed.
(This must be set up in addition to the previous challenges; do not remove,
replace, or undo the previous challenge tasks yet. Note that you might be
asked to create multiple distinct TXT records with the same name. This is
permitted by DNS standards.)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue ← 「Enter」キーを押す前に、上記のTXT情報をDNSサーバに登録
Waiting for verification...
Cleaning up challenges
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/usite.com/fullchain.pem ← 取得したSSL証明書
Your key file has been saved at:
/etc/letsencrypt/live/usite.com/privkey.pem ← 取得した秘密鍵
Your certificate will expire on 2023-03-22. 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"
- 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
3 DNSに検証情報を登録する方法
利用中のサイトのDNSにログインして、上記の“2”の検証情報をDNSに登録します。登録用「TXT」レコードの形式は以下の通りです。
txt _acme-challenge.usite.com xxxxxxxxxxxxxxxxxxxxxxxxxxxxx-dXXxxxXXxxoio
txt _acme-challenge.usite.com xxxxxxxxxxxxxxxxxxxxxxxxxxxxx-aXXxxxXXxx4Bs
登録した結果を確認したい場合は、“nslookup”コマンドを使います。具体的に言うと、以下の通りです。
[root@usite ~]# nslookup -q=txt _acme-challenge.usite.com
Server: dns.google
Address: 8.8.8.8
Non-authoritative answer:
_acme-challenge.usite.com text =
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxx-dXXxxxXXxxoio"
_acme-challenge.usite.com text =
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxx-aXXxxxXXxx4Bs"
4 Apacheサーバの設定
ワイルドカード付きのSSL証明書を取得したあとに、Apacheサーバ上に設定することが必要です。方法は以下の通りです。
[root@usite ~]# vi /etc/httpd/conf.d/ssl.conf ← SSL設定ファイルの編集
# Server Certificate:
# Point SSLCertificateFile at a PEM encoded certificate. If
# the certificate is encrypted, then you will be prompted for a
# pass phrase. Note that a kill -HUP will prompt again. A new
# certificate can be generated using the genkey(1) command.
SSLCertificateFile /etc/letsencrypt/live/usite.com/cert.pem ← 公開鍵の指定
# Server Private Key:
# If the key is not combined with the certificate, use this
# directive to point at the key file. Keep in mind that if
# you've both a RSA and a DSA private key you can configure
# both in parallel (to also allow the use of DSA ciphers, etc.)
SSLCertificateKeyFile /etc/letsencrypt/live/usite.com/privkey.pem ← 秘密鍵の指定
# Server Certificate Chain:
# Point SSLCertificateChainFile at a file containing the
# concatenation of PEM encoded CA certificates which form the
# certificate chain for the server certificate. Alternatively
# the referenced file can be the same as SSLCertificateFile
# when the CA certificates are directly appended to the server
# certificate for convinience.
SSLCertificateChainFile /etc/letsencrypt/live/usite.com/fullchain.pem ← 証明書の指定
上記の設定を完了したあとに、Apacheサーバをリロードすることが必要です。方法は以下の通りです。
[root@usite ~]# systemctl reload httpd ← Apacheサーバのリロード
以上の方法を使って、ワイルドカード付きの“Let‘s encrypt”のSSL証明書を取得し、設定することができます。本文では、以下のWebページを参考にしています。
- https://ex1.m-yabe.com/archives/4647
- https://laboradian.com/use-wildcard-with-letsencrypt/