Log
Accessing Virtual Hosts from Virtual PC
I often use Apache virtual hosts on my Mac when developing sites—I almost always prefer to do initial development on my machine and then upload to the public server for browser testing and final tweaking. Since I don’t want to do anything with dns entries, I simply edit my hosts file to point the development url to localhost. As a result of this, I have a lot of virtual hosts defined in httpd.conf and corresponding entries in my hosts file.
For instructions on setting up virtual hosts, see mezzoblue’s “Virtual Hosts for Dummies”. One caveat with the article though; see below.
Yesterday, I needed to test such a site in IE running in VirtualPC. (For various reasons, I didn’t want to set it up on a public server to do the testing.) I followed the expected procedure of editing the hosts file on the Virtual PC (located in C:\Windows\system32\drivers\etc\hosts), using my Mac’s IP address as the destination IP. No go. Everything worked perfectly outside of VirtualPC, but attempting to access the site from Virtual PC resulted in a 404 error. This meant that it connected, but the server couldn’t find the file. I checked the Apache error log and discovered that Apache was looking for the file in the main webroot (/Library/WebServer/Documents/). Accessing the development url without a subdirectory or filename gave me the apache install page.
After pulling out my hair for quite some time (and incorrectly assuming that Windows was sending the request incorrectly), I finally discovered the problem. When I set up my virtual hosts, I had made my VirtualHost directives as described in the mezzoblue article:
<VirtualHost 127.0.0.1>
ServerName dev.local
...
</VirtualHost>
This is wrong! It works fine when the request is coming from localhost, ie. the same machine, but when the request comes from another machine (or a virtual machine), Apache treats the request as if it were requesting the first virtual host defined with 127.0.0.1. So my request was directed to the first virtual host defined, which happened to be localhost.
The solution: use * (or *:80 to specify port 80) instead of 127.0.0.1 in the VirtualHost directive as such:
<VirtualHost *>
ServerName dev.local
...
</VirtualHost>
09/01/06 09:34AM Geekiness Macintosh
Recently Played on iTunes
-
“Abierto”
Soul Food Taqueria
Tommy Guerrero
10/06/08 16:28 -
“Hit Or Miss”
Punk Rock Days: The Best Of DBL
Down By Law
10/06/08 16:25 -
“Start!”
Compact Snap
The Jam
10/06/08 16:22