[Zope] Virtual Hosting configuration for Zope

Alan Capesius alanc@tech-world.com
Wed, 21 Mar 2001 23:01:26 -0600


I've put together the following solutions for virtual hosting of domains
and I'm looking for some feedback from the list.

The solution uses TinyTable, Virtual Host Monster and AccessRule and a
DTML method to process all inbound requests by domain name similar to
the way in which SiteRoot script things. The best part is that once set,
the AccessRule does not need to be modified to add new hosts. Host to
folder mapping is performed via entries in the TinyTable, the rest of
the configuration is static. I would think it would be simple to
implement something like this as a product, though it is beyond my
current skill set.

I'd like to enhance it a bit further so that it can handle hostnames in
addition to just domain names. I'd also be happy to hear any feedback on
this.

Tested with Zope 2.3.0 and TinyTable 0-8-2.
Virtual Host Monster and AccessRule support are built into 2.3.0


Here it is:

Create a folder in Root called VHosts
Inside VHosts create a folder for each Virtual host
Inside each new Virtual host's folder , create a Virtual Host Monster
called VHM

Inside VHosts, create a TinyTable called HostsTable
Give the Tiny Table the following columns : domain, folder
Create records for domain to folder mapping as shown here:
"domain1.com", "Folder1"
"domain2.com", "Folder2"
Where the domain names are the virtual names for your server and the
folder names are the folders created inside VHosts.
Entries are CASE SENSITIVE and MUST match the folder names created in
the earlier step. Enter all domains in lower case.

Inside VHosts create the following DTML Method:
Name: gethostfolder
<dtml-in "VHosts.HostsTable(domainname)">
  <dtml-return folder>
<dtml-else>
  <dtml-return "'NULL'">
</dtml-in>

In the Root, create a DTML called AccessRule
AccessRule in Root Folder
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
<dtml-let
hostname=3D"_.string.split(_.string.lower(_.string.split(HTTP_HOST,
':')[0]),'.')[-2:]"
          domainname=3D"hostname[0] + '.' + hostname[1]"
          vhmcode=3D"VHosts.gethostfolder(_.None, _, =
host=3Ddomainname)">

<dtml-if "vhmcode<>'NULL'">
  <dtml-if "_.string.split(_.string.lower(PATH_INFO),
'/')[-1:]=3D=3D['manage'] or
            _.string.split(_.string.lower(PATH_INFO),
'/')[-1:]=3D=3D['manage_main'] or
            _.string.split(_.string.lower(PATH_INFO),
'/')[-1:]=3D=3D['manage_workspace'] ">
    <dtml-if "TraversalRequestNameStack[-2:]<>[vhmcode,'VHosts']">
      <dtml-call "REQUEST['TraversalRequestNameStack'].extend([vhmcode,
'VHosts'])">
    </dtml-if>
  <dtml-else>
    <dtml-call "REQUEST['TraversalRequestNameStack'].extend(['VHM',
vhmcode, 'VHosts'])">
  </dtml-if>
</dtml-if>

</dtml-let>

It should look like this:
Root-
  AccessRule
  VHosts-
       HostsTable
       gethostfolder
       Folder1-
             VHM
             index_html
       Folder2-
             VHM
             index_html





Security Settings:
gethostfolder method:   no anonymous access, proxy as manager, manager
has full rights.
HostsTable: No anonymous access, manager full rights
AccessRule: Proxy as manager

Now, to enable the system, Use the Root folder's Add->SetAccessRule
option and enter "AccessRule" (without quotes) and click Set.
Requests for domain1 will be drawn from Folder1, 2 from 2 etc..
Managent of the virtual domain will show only the VHosts folder contents
for the selected site.
Management of the root site will show the root.
Access to unsupported domains will fall back to root. (perhaps to be a
redirect to a 404 page in the future)

Display the mappings with /VHosts/HostsTable or via the management
interface.

Use http://hostname/_SUPPRESS_ACCESSRULE/manage to deactivate the
AccessRule if you have any problems accessing the system.

All feedback welcome. To the list please.

Alan Capesius, MCSE
Tech World, Inc.
http://twsite.bizland.com/zopetips.htm