ドキュメントルート=WordPressのディレクトリとしている時にWordPressの構成ファイルと一緒に別のWeb用ディレクトリを置きたくない、でもサーバは同じところにしたい、という時など
ドメイン管理会社でサブドメイン(wwwなど)をAレコード、同じIPアドレスで設定する
まだSSL証明書を取していないのでSSL設定部分はコメントにしてApacheのサブドメイン設定ファイルを作成する
vi /etc/httpd/conf.d/subdomain.conf
<VirtualHost *:80>
ServerName sub.example.net
DocumentRoot "/home/example/sub"
RewriteEngine on
</VirtualHost>
<Directory "/home/example/sub">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<VirtualHost *:443>
ServerName sub.example.net
DocumentRoot "/home/example/sub"
# SSLEngine on
#SSLCertificateFile /etc/letsencrypt/live/sub.example.net/cert.pem
#SSLCertificateKeyFile /etc/letsencrypt/live/sub.example.net/privkey.pem
#SSLCertificateChainFile /etc/letsencrypt/live/sub.example.net/chain.pem
# SSLProtocolとSSLProtocol設定は環境に合わせて設定
# SSLProtocol all -SSLv2 -SSLv3
# SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
# SSLProtocol -all +TLSv1.2 +TLSv1.3
# SSLCipherSuite HIGH:!aNULL:!MD5:!3DES:!CAMELLIA
# SSLHonorCipherOrder on
<Directory "/home/example/sub">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Apacheを再起動
systemctl restart httpd
Let’sEncryptの証明書を取得
certbot certonly --webroot -w /home/example/sub -m sub@example.net -d sub.example.net -n --agree-tos
/etc/httpd/conf.d/subdomain.confのSSL設定部分のコメントを外す
Apacheを再起動
systemctl restart httpd
