# apache virtual hosts issue on windows - please explain

This problem has never occurred in the past (i have tried this many times) but this time,

ALL virtual hosts defined in the virtual-hosts.conf file in the apache installation directory direct the browser to the apache server documentRoot directory.

These are the virtual hosts defined

NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
ServerName dev.a.local
ServerAlias dev.a.local
DocumentRoot "D:/wwwroot/a/public"
ErrorLog "logs/a.log"
CustomLog "logs/a-access.log" common

<Directory "D:/wwwroot/a/public">
AllowOverride All
# Controls who can get stuff from this server.
Order allow,deny
Allow from all
DirectoryIndex index.php
</Directory>
</VirtualHost>

<VirtualHost *:80>
ServerName dev.b.local
ServerAlias dev.b.local
DocumentRoot "D:/wwwroot/b/public"
ErrorLog "logs/b.log"
CustomLog "logs/b-access.log" common

<Directory "D:/wwwroot/b/public"s>
AllowOverride All
# Controls who can get stuff from this server.
Order allow,deny
Allow from all
DirectoryIndex index.php
</Directory>
</VirtualHost>


I have modified the hosts file and added

127.0.0.1 dev.a.local
127.0.0.1 dev.b.local


When i try to access dev.a.local or dev.b.local i am directed to the documentRoot of apache defined in httpd.conf.

-
have you restarted apache after make the config changes? –  Mike May 29 '12 at 19:41
yes i did restart. –  andreas May 29 '12 at 19:41
which logs does your traffic turn up in? is that config a direct copy and paste or did you edit it? is that config file included somewhere in your http.conf? –  EightBitTony May 29 '12 at 19:59
Please provide the output of C:\path\to\apache.exe -S. –  Shane Madden May 29 '12 at 19:59
@Shane id have stuck that in an answer, its bound to lead to the solution –  Tom H May 29 '12 at 20:50

I've never seen multiple

  <VirtualHost *:80>


entries before, and would be very surprised if this actually separated the traffic. Also, setting a serverAlias the same as the servername is definitely redundant. And your example does not show the serverRoot configuration (hopefully this different from the documentRoot or you're going to have big problems). Try:

NameVirtualHost *:80

<VirtualHost dev.a.local>
DocumentRoot "D:/wwwroot/a/public"
ErrorLog "logs/a.log"
CustomLog "logs/a-access.log" common

<Directory "D:/wwwroot/a/public">
AllowOverride All
# Controls who can get stuff from this server.
Order allow,deny
Allow from all
DirectoryIndex index.php
</Directory>
</VirtualHost>

<VirtualHost dev.b.local>
DocumentRoot "D:/wwwroot/b/public"
ErrorLog "logs/b.log"
CustomLog "logs/b-access.log" common

<Directory "D:/wwwroot/b/public">
AllowOverride All
# Controls who can get stuff from this server.
Order allow,deny
Allow from all
DirectoryIndex index.php
</Directory>
</VirtualHost>

-
thanks. just tried your suggestion/solution. No luck. –  andreas May 29 '12 at 21:42
@symcbean The host specification in the vhost needs to match the NameVirtualHost directive for name-based hosting to work. –  Shane Madden May 30 '12 at 0:40

The file that you've defined those <VirtualHost> blocks in is not being included in your configuration (unless the service configuration is defining a custom config path in its command line - verify that in the services MMC snap-in).

If the content that you've posted is the entire contents of the file, then it should be safe to include it directly from your main configuration.

Include /path/to/virtual-hosts.conf


Or, if the virtual-hosts.conf file contains all of the basic server settings as are in your main config file, then it may be intended as a drop-in replacement for your current main config file?

The other option is to just put your configuration of the vhosts in the main configuration file instead of the virtualhosts config file where you have them currently.

-