Apacheでバーチャルホストを設定する方法を紹介します。
バーチャルホストを設定することで、1つのサーバーに複数のホストを設置することができます。
通常一つのサーバーにサイトなどを複数設置するため、このバーチャルホストの設定が必要になります。
今回は、FreeBSDのOSを使用してApacheの設定例を紹介します。
FreeBSDでもLinuxでも基本的に記述方法は同じです。
ファイルのパスなどが異なるだけなので、他のOSの場合も同様に設定します。
変更するファイルは、httpd.confとhttpd-vhosts.confの2つです。
まずは、httpd.confを編集して、httpd-vhosts.confを読込むよう設定します。
httpd.confの記述例
# Virtual hosts
Include etc/apache22/extra/httpd-vhosts.conf
次にhttpd-vhosts.confにバーチャルホストの設定を記述します。
httpd-vhosts.confの記述例
<VirtualHost *:80>
ServerAdmin info@pb-times.jp
ServerName pb-times.jp
ErrorLog /home/pb-times/logs/error_log
CustomLog /home/pb-times/logs/access_log combined
SuexecUserGroup user group
DocumentRoot /home/pb-times/public
<Directory "/home/pb-times/public">
Options None
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ScriptAlias /cgi-bin/ "/home/pb-times/cgi-bin/"
<Directory "/home/pb-times/cgi-bin">
Options ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Apache、バーチャルホストの設定が正しく行われたか確認をします。
「OK」と表示されれば正しく設定されています。
# apachectl configtest
Syntax OK
Apache、バーチャルホストの設定が正しく行われたことを確認したら、Apacheを再起動します。
# apachectl graceful