XAMPPでVirtualHostを使う時のメモです。
※バージョンはXAMPP:1.7.7/Apache:2.2.21 (Win32)
※ 設定内容はあくまでもローカルで開発/テスト用ですのでご注意あれ。
インストール先のディレクトリを D:\xampp とします。
Apacheの設定
httpd.confの位置
D:\xampp\apache\conf\httpd.conf
ドキュメントルートは↓
D:\xampp\htdocs
ログの位置は↓
D:\xampp\apache\logs
※confファイルのパスの区切りは\(バックスラッシュもしくは¥(円記号))でなくて/(スラッシュ)にする。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
C:\xampp\apache\conf\extraの下の.confファイルもにもいろいろ設定書かれてる。 ├ httpd-ajp.conf →プロキシ関連? ├ httpd-autoindex.conf ├ httpd-dav.conf ├ httpd-default.conf →TimeoutやKeepAliveの設定とか ├ httpd-info.conf ├ httpd-languages.conf ├ httpd-mpm.conf ├ httpd-multilang-errordoc.conf ├ httpd-perl-asp.conf ├ httpd-perl-usb.conf ├ httpd-perl.conf ├ httpd-proxy.conf ├ httpd-ssl.conf →SSL関連 ├ httpd-userdir.conf →ユーザディレクトリの設定 デフォルトでは My Documents/My Website に置かれるもよう ├ httpd-vhosts.conf ├ httpd-xampp.conf →XAMP特有のなにか └ startup.pl |
全部は読みきれませんので使うもののみ。
VirtualHostを設定する
Apacheは一旦Stopボタン押して停止
httpd-vhosts.confを開いてコメントアウトされてるVirtualHostの部分を参考に適宜変更
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
NameVurtualHost *:80 <VirtualHost *:80> ServerAdmin postmaster@sample01.test DocumentRoot "D:/www/vhost/sample01.test/public_html" ServerName sample01.test ServerAlias www.sample01.test ErrorLog "D:/www/vhost/sample01.test/logs/error.log" CustomLog "D:/www/vhost/sample01.test/logs/access.log" combined <Directory "D:/www/vhost/sample01.test/public_html"> Options FollowSymLinks AllowOverride all Order deny,allow Allow from all </Directory> </VirtualHost> <VirtualHost *:80> ServerAdmin postmaster@sample02.test DocumentRoot "D:/www/vhost/sample02.test/public_html" ServerName sample02.test ServerAlias www.sample02.test ErrorLog "D:/www/vhost/sample02.test/logs/error.log" CustomLog "D:/www/vhost/sample02.test/logs/access.log" combined <Directory "D:/www/vhost/sample02.test/public_html"> Options FollowSymLinks AllowOverride all Order deny,allow Allow from all </Directory> </VirtualHost> |
設定できたらApacheを起動。
Startボタン押してもRunningって出なかったらどっか設定ファイルが間違っている。
DocumentRootに存在しないディレクトリを設定してるとか。
hostsファイルにローカルIPとドメインの対応づけをする。
1 2 |
127.0.0.1 sample01.test 127.0.0.1 www.sample01.test |
Windows7でのhostsファイルのありかは C:\Windows\System32\drivers\etc\hosts なのですが、直接は開けない!
メモ帳を管理者権限で実行して(スタートメニューのメモ帳かメモ帳のexeを選択して右クリック→管理者として実行)、メニューからhostsファイルを指定して開く。
そうしないと開けない&保存できない。
設定できてるかコマンドオプションで確認
1 2 3 4 5 6 7 8 |
D:\xampp\apache\bin>.\httpd.exe -S VirtualHost configuration: wildcard NameVirtualHosts and _default_ servers: _default_:443 localhost (D:/xampp/apache/conf/extra/httpd-ssl.conf:80) *:80 is a NameVirtualHost default server sample01.test (D:/xampp/apache/conf/extra/httpd-vhosts.conf:3) port 80 namevhost sample01.test (D:/xampp/apache/conf/extra/httpd-vhosts.conf:3) port 80 namevhost sample02.test (D:/xampp/apache/conf/extra/httpd-vhosts.conf:18) |
ブラウザで確認。
ここでサーバが見つかりませんでした というエラーが出たらhostsファイルの設定が間違っている。
public_htmlの下にindex.htmlを置いてブラウザで確認。
Access forbidden!と表示され Error 403 が出る。
そんでエラーログに↓とログされている場合。
client denied by server configuration
公開ディレクトリへのアクセス許可がされていない。
↓この部分を確認
1 2 3 4 5 6 |
<Directory "D:/www/vhost/sample01.test/public_html"> Options FollowSymLinks ← シンボリックリンク使う場合は必要(Winで使えるかは未確認) AllowOverride all ← .htaccess使う場合は必要 Order deny,allow ← アクセス許可の順序。ダメ、許可の順 Allow from alll ← 全てのホストからのアクセスを許可する </Directory> |
詳しいApacheの設定ファイルの書き方はまあApacheのドキュメントサイトを参考に。