[thelist] multiple sites on localhost with Apache?

Phil Turmel philip at turmel.org
Wed Oct 27 12:49:27 CDT 2004


You're on the right track....

1) Your local DNS server (or hosts file if the list is 
short) just needs to wildcard all domains back to 
  It won't actually have any information on directory 
structures.  (I'm not a Mac person, so I can't recommend a 
DNS server package that would be suitable.)

2) Apache's configuration file needs a virtual host section 
for each domain name you are trying to mimic, with its 
"DocumentRoot" property pointing to the correct physical 
directory.  Note that a VirtualHost section can specify 
aliases, so you can use a single vhost to handle both 
www.123.com and 123.com.

3) The very first vhost section will be the catch-all for 
any domains you don't have copies of.  Put the appropriate 
explanatory page as its index.html, with a rewrite rule in 
just that host to force all links to the index.

Thanks to HTTP 1.1, the browser passes the presumed host 
name to the webserver independant of the IP address, so 
apache can figure out which document root to use without 
having unique IPs.

Note that once an apache configuration file specifies 
virtual host behavior, the global servername, document root, 
etc, is ignored.  Only the servernames and document roots 
specified inside vhost sections work.

Phil T.

Stephen Rider wrote:
> Hi all --
> I'm trying to set up a web kiosk on an old iMac.  The trick is that this 
> computer will be completely offline and I need to host a couple 
> different sites to it using Apache.
> If it were only one site, I would just throw the files on the hard drive 
> and serve them up as, but I need to find a way to set it up so 
> that if the browser looks for www.abc.com Apache will serve up the 
> contents of /Sites/abc/ , and if www.123.com it will point to 
> /Sites/123/  (obviously these are example addresses).
> Is there a way to do this?  I'm sure it will involve Virtual Domains, 
> which understand only vaguely, but won't I also have to set up a "fake" 
> local DNS or somesuch to point the browser to the directories?
> All of the sites I need to use utilize Root addressing in some places, 
> so I can _not_ use
> and
> (Note:  I'm actually using Apache 2.0.52 via the "Complete Apache" 
> package, not the 1.x version that comes with OS X.  If need be I can 
> always switch back to the built-in version.)
> All help is appreciated.  Thank You! :)
> Steve

More information about the thelist mailing list