[CentOS] CentOS7.xとApache2.4でVirtualHost設定(本番環境)

CentOS7.xとApache2.4でバーチャルホストを設定する方法です。
Contents
httpd.confの設定変更
/etc/httpd/conf.d/httpd.confを以下のように変更します。
1 2 3 4 5 6 7 8 9 |
# 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化した設定です。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<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が出ますので注意)関連記事
- [Linux] Apache(httpd.conf)の設定
- [VirtualBox] CentOS7.xとApache2.4でVirtualHost設定(ローカル環境)
- [Let’s Encrypt] CentOS7.xにインストールする方法
- [Linux] CentOSにApache(httpd)をインストールし基本的な設定を行う
- [CentOS] 7.xにphpMyAdminをインストール