CentOS7.xとApache2.4でバーチャルホストを設定する方法です。
httpd.confの設定変更
/etc/httpd/conf.d/httpd.confを以下のように変更します。
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other
# <Directory> blocks below.
#
<Directory />
Allowoverride All
#AllowOverride none
Require all denied
</Directory>
AllowOverride noneをAllowoverride Allに変えました。
バーチャルホスト設定
/etc/httpd/conf.d/の中にtest.example.com.confというファイルを作ります。
これだけで自動に設定が読み込まれます。
下記はLetsEncriptを使いSSL化した設定です。
<VirtualHost xxx.xxx.xxx.xxx:80>
DocumentRoot /var/www/html/test.example.com
ServerName test.example.com
</VirtualHost>
#SSL(LetsEncript設定)
<VirtualHost test.example.com:443>
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/test.example.comt/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/test.example.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/test.example.com/chain.pem
DocumentRoot /var/www/html/test.example.com
ServerName test.example.com
</VirtualHost>
<Directory "/var/www/html/test.example.com/">
Require all granted
AllowOverride ALL
</Directory>
設定が終わったら systemctl restart httpd でApacheを再起動します。
.htaccessのベーシック認証ファイルを置いて正しく動くかのテスト
index.html または index.php ファイルにhelloを記載し、表示されるかテスト
(index.htmだとInternal Server Errorが出ますので注意)