You are not logged in Log in Join
You are here: Home » Members » jmeile » How to do virtual hosting without using Apache

Log in
Name

Password

 

How to do virtual hosting without using Apache

 

Created by jmeile . Last modified 2006-06-16 09:43:47.

Describes an alternative to do it on zope versions older than 2.5.x. Newer versions should use a VirtualHostMonster.
Somebody told me that there is a better way of doing this with just a VirtualHostMonster in your root folder, then define the virtual domains in the mappings tab. Unfortunatelly, by that time I've already done this How-To. Please note that the last solution will only work with versions newer than 2.5.x. Previous versions don't have the mappings tab, so on this case, you can use my solution.








After a lot of reading, I found a solution that makes virtual hosting combining TinyTables, AccessRules and SiteAccess without using Apache.

I took some ideas and code from the SiteAccess info page and this Zope-Tip.

Differences:

There are three main differences between the previously mentioned How-to and my solution:

  • Instead of using VirtualHostMonster objects, I use SiteRoot objects.

  • I don't fix the virtual host to be in the VHosts folder. You can put it wherever you want (ie: folder1/folder2/.../foldern/websiteroot). So, your paths can be as long as Zope and TinyTable allow them.

  • Your virtual links are not limited to have only two parts. For example, you can type links like: www.mylink.com or www.mylink.com.co and the code will automatically detect it.

Precautions:

Because AccessRules are not only powerful but also dangerous, as all the How-Tos and Tips that I've read start, I've to repeat something here:

Make everything on a test site and copy its Data.fs* files, so, if you make a mistake you can overwrite them. If I were you, I wouldn't do it in my main Zope Site before I'd be sure that it works because you could block your Zope if you set an invalid AccessRule and your site would be off-line. Anyway, just in case, if you can't access your manage interface, type the following:

http://www.mysite.com/_SUPPRESS_ACCESSRULE/manage

and then set the AccessRule to "No Access Rule" there.
Before you put everything on your main zope site, make a backup, so you can undo the changes after.

Steps to activate Virtual Hosting:

  • Point your virtual servers to your Zope server. (Don't ask me how, somebody did it for me).

  • Install the TinyTables product.

  • Go to the root folder of your virtual host, create there a SiteRoot object, and leave the Base and Path fields empty.

  • Then create a TinyTable with the following attributes:

    Id: VirtualLinks
    Title: Write virtual links and their local paths here
    Columns: domain path

    Inside this table you should put your virtual hosts:
    Note that here I'm using a domain with three parts, you can also use one like: mysite.com or whatever you want. Also remember to separate them by typing enter and don't put your default Zope's link here.
    Don't give access to anonymous and give manager all the rights.

  • Create the following dtml-method in the Root Folder of your Zope:

    Id: getDomainPath
    Title: Looks for a match on the VirtualLinks table


    Don't give access to anonymous, set the proxy as manager and give manager all the rights.

  • Create the following dtml-method in the Root Folder of your Zope:

    Id: redirectToHost
    Title: Redirects all the requests to the right virtual server


    Set the proxy as manager and set it as the AccessRule and that's all.

Recommended Links:

If there is a bug or something is missing, please let me now:
Here you'll find more how-tos and products I've published.