2月
21
2011
ローカルでヴァーチャルドメイン
ローカル環境でバーチャルドメインの設定をする。
domain1とdomain2と2つサイトを
http://localhost/domain1/
http://localhost/domain2/
のようにするのでもいいが、なるべく
http://domain1.localhost/
http://domain2.localhost/
でアクセスできる方がなにかと都合が良い!!
と言うことでApacheを設定
まずはapache/conf/httpd.confでヴァーチャルドメインの設定
#NameVirtualHost *:80のコメントアウトをはずす。
なければ追記。
<Directory “C:/localhost”>
order deny,allow
allow from ALL
</Directory>
order deny,allow
allow from ALL
</Directory>
があるあたりに
<VirtualHost *:80>
DocumentRoot C:/localhost/domain1/
ServerName domain1.localhost
</VirtualHost<
<VirtualHost *:80>
DocumentRoot C:/localhost/domain2/
ServerName domain2.localhost
</VirtualHost>
DocumentRoot C:/localhost/domain1/
ServerName domain1.localhost
</VirtualHost<
<VirtualHost *:80>
DocumentRoot C:/localhost/domain2/
ServerName domain2.localhost
</VirtualHost>
と設定してやる。
次にWindows側の設定。
C:\WINDOWS\system32\drivers\etc\hostsを開く
127.0.0.1 localhost
となっているので
127.0.0.1 localhost
127.0.0.1 domain1.localhost
127.0.0.1 domain2.localhost
127.0.0.1 domain1.localhost
127.0.0.1 domain2.localhost
とヴァーチャルドメイン名を追加。
これでdomain1.localhostとdomain2.localhostをローカルの127.0.0.1へ振るようにする。
これでApacheを再起動すれば
http://domain1.localhost/
http://domain2.localhost/
でアクセスできます。
《参考サイト》
WinXPローカル環境で複数ドメイン管理