SAN(Subject Alternative Name)証明書の使い方です。
Ubuntu 20.04 で確認しました。
コマンドのインストール
sudo apt install certbot
次の4つのドメインが同じIPに割り当てられているとします。
test.example.com
test2.example.com
test3.example.com
test4.example.com
証明書の取得
folder="/var/www/html/public_test"
mail="admin@example.com"
certbot certonly \
--webroot -w $folder -d test.example.com \
--webroot -w $folder -d test2.example.com \
--webroot -w $folder -d test3.example.com \
--webroot -w $folder -d test4.example.com \
--email $mail
このコマンドを実行すると、
/etc/letsencrypt/live/test.example.com
に証明書が作成されます。
Apache2 の設定ファイル
/etc/apache2/sites-available/test.example.com-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName test.example.com
ServerAlias test2.example.com
ServerAlias test3.example.com
ServerAlias test4.example.com
DocumentRoot /var/www/html/public_test
ErrorLog ${APACHE_LOG_DIR}/error_ssl.log
CustomLog ${APACHE_LOG_DIR}/access_ssl.log combined
<Directory /var/www/html/public_test>
AllowOverride none
Require all granted
</Directory>
SSLCertificateFile /etc/letsencrypt/live/test.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/test.example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
シンボリックリンクの作成
cd /etc/apache2/sites-enabled
sudo ln -s ../test.example.com-le-ssl.conf .
設定の確認
sudo apache2ctl configtest
Apache2 の再起動
>```bash
sudo systemctl restart apache2
証明書の取得は次のようにすることもできます。
folder="/var/www/html/public_test"
mail="admin@example.com"
certbot certonly \
--apache -d test.example.com \
--apache -d test2.example.com \
--apache -d test3.example.com \
--apache -d test4.example.com \
--email $mail
次のライブラリーをインストールする必要があります。
sudo apt install python3-certbot-apache