[Zope] VirtualHostMonster w/ ZServer

Walter Miller wmiller@macromedia.com
Wed, 7 Feb 2001 10:07:14 -0800


If I understand your example properly, when someone types in www.foo.com,
the Access Rule I have in the root directory uses the Python script to send
requests to the /vhosts/foo directory.  I tried that and got it working as a
test one level up in a directory I called /root because I didn't want to
risk locking myself out, i.e. /root/vhosts/foo.

Now, the second part of the equation is to put the VHM in the directory you
want to be the root so all objects in that directory return logical path of
/ instead of their true physical path.  In my example above, putting a VHM
in the /root/vhosts/foo directory changes the paths of the objects in
/root/vhosts/foo to just /root when using www.foo.com/root as the URL.  I
got this working as well.

The one question I have is regarding the naming convention of the VHM.  It
doesn't seem to matter what the name/ID of the VHM is as long as
"VirtualHostRoot" is used in the requesting URL.  Likewise, you can change
"VirtualHostRoot" in the requesting URL to something else like "testVHM" and
as long as the VHM is called "testVHM", it works.  Is there a preferred
naming convention?

Walter

> What's the "best" way to set up a few virtual hosts using only ZServer?
For
> example, to make www.mysite.com/vhosts/foo and www.mysite.com/vhosts/bar
> appear as www.foo.com and www.bar.com respectively.  Do I need a SiteRite
> product or can this work with just a VirtualHostMonster?

Neither SiteRoots nor VirtualHostMonsters can do the job by themselves.
They both need somebody doing the first half of the virtual host mapping --
sending  requests for www.foo.com to /vhosts/foo.  Apache can do this, but
if you want a bare ZServer, you'll need to use an Access Rule.  Setting the
following Script as root Access Rule should do it, in conjunction with a
VHM:

## Script (Python) "vhost_access"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=
##parameters=self, req, resp

##title=Virtual Host Access Rule
##
host = req['HTTP_HOST']
stack = req['TraversalRequestNameStack']
# Put path elements on the stack in reverse order.
if host == 'www.foo.com':
    stack.extend(['VirtualHostRoot', 'foo', 'vhosts'])
elif host == 'www.bar.com':
    stack.extend(['VirtualHostRoot', 'bar', 'vhosts'])

Cheers,

Evan @ digicool & 4-am