Virtual Host configuration on Apache2 and Windows
For a long time I have had an ongoing battle in my head about whether to use Linux or Windows as my webserver OS. Linux seems to be able to provide speed and stability while Windows seems to provide manageability. Can you hear the Linux goofs whining about how powerful Linux is? That's great, let me know when you are done explaining why video is so painful in X… why I can't simply open a remote video session… why daily tasks require knowledge that the vast bulk of Windows users will never even think of having… OK, I'm done for now.
So this weekend I was screwing around and testing out some "stuff" at home. I now have a Windows box that seems to be workin' pretty good but it was a bit of a bitch when it came to the virtual hosts part of the Apache config. I wanted to setup Apache so that it would have a default web page that would appear if someone tried to access the server without using one of the domain names I actually own. I quickly ran through my httpd.conf file and threw in some virtual hosts, but it was not doing what I expected. It would always show me the FIRST virtual host that I defined. My searches returned a number of people having similar issues but it turned out that I had a combination of their multiple problems. Here is a sample clip of a httpd.conf file and some tips to get your Apache working (if this is what you have screwed up too).
# Use name-based virtual hosting.
NameVirtualHost *:80
# Default Website
DocumentRoot C:/path/to/files
CustomLog C:/logs/default.log combined
# Entry for site001.com
ServerName site001.com
DocumentRoot C:/path/to/site001
CustomLog C:/logs/site001.log combined
# Entry for site002.com
ServerName site002.com
DocumentRoot C:/path/to/site002
CustomLog C:/logs/site002.log combined
# Entry for site003.com
ServerName site003.com
DocumentRoot C:/path/to/site003
CustomLog C:/logs/site003.log combined
Tip #1 – See how the first directive starts off with NameVirtualHost *:80 and each subsequent VirtualHost directive has *:80 after it? Apparently this is required syntax for Apache2. I am under the impression that you did not have to match the *:80 part in Apache1 but that ain't the case anymore.
Tip #2 – Notice that all the backslashes are not BACKslashes? I have noticed that you can use either slash in the Windows version of Apache but it seems to work better if you consistently use the forward slashes. You can choose to use either one but I would suggest choosing one and sticking with it. If you have PHP installed it likely added itself to the bottom of your httpd.conf using forwardslashes.
Tip #3 – If you have a ServerName directive in your config file (and you probably do have one near the top somewhere) then it can't be the same as any of your virtual host ServerName or ServerAlias directives. If you installed Apache with the Windows installer (and you may very well have) then you might find a ServerName site001.com statement that is screwing you up. This one might be hard to track since it will only screw up ONE of your virtual hosts.
