You are not logged in Log in Join
You are here: Home » Members » fritz » Configure Apache Virtual Hosts and Zope using SiteRoot

Log in
Name

Password

 

Configure Apache Virtual Hosts and Zope using SiteRoot

Introduction

Greetings! This is my first time to create this How-To so please bear with me
I just would like to help others out in creating a "harmonious" interaction between Apache and Zope using VirtualHosts and SiteRoot.

Purpose

(1)
Suppose you have http://www.foo.com and you want to have cgi scripts while you serve the main website in Zope.
Scenario:
http://www.foo.com would serve your Zope content.
http://www.foo.com/cgi-bin/ would serve your CGI scripts.

(2)
This will also hide the port number and folder of the zope site.
Scenario:
http://www.foo.com will be visible to your visitors.
http://www.bar.com:8080/folder/ is the actual server and folder.

Assumptions

  • Apache is installed with DSO support.
  • Zope is already installed with the SiteAccess Product. (We need SiteRoot)
  • You know how to use mod_rewrite or create rewrite passes.
    If not, please check this out first: Apache.org - mod_rewrite

Procedure

Step 1

Better setup the rewrite passes first BEFORE installing the SiteRoot.
We need Evan Simpson's SiteAccess product (SiteRoot). Fortunately it is already included in Zope version 2.3 and higher.

If you are using a Zope version I advice to upgrade it first. BUT a lot of people have advised not to upgrade yet to version 2.4 if you are not ready to do a lot of dependency upgrades. Oh well, you can't please them all. It just depends on you.

Open your httpd.conf or access.conf of Apache.
Look for these 4 lines to make sure mod_rewrite and mod_proxy has been installed:

LoadModule rewrite_module libexec/mod_rewrite.so
AddModule mod_rewrite.c
LoadModule proxy_module libexec/libproxy.so
AddModule mod_proxy.c

Next, add the italicized lines in your virtual hosts config: (Named Virtual Hosts will be used as an example.)

NameVirtualHost 123.456.789.0

<VirtualHost 123.456.789.0>
   ServerName www.foo.com
   ServerAdmin [email protected]
   DocumentRoot /folder/subfolder
   ...

   RewriteEngine on
   RewriteLog "/folder/rewrite_log"
   RewriteLogLevel 1

   RewriteRule ^/static_page_folder1/ - [L]
   RewriteRule ^/static_page_folder2(.*) /static/page/folder/not/in/root/folder$1 [L]

   RewriteRule ^/(.*) http://www.bar.com:8080/zope_folder/$1 [P,L]

</VirtualHost>

If you need help with mod_rewrite: Apache.org - mod_rewrite

In summary,
RewriteEngine on - activates the rewriting (must be in every virtual host)
RewriteLog - the location to put the rewrite logs (useful for debugging)
RewriteLogLevel - determines the level of rewrite logging

RewriteRule ^/static_page_folder1/ - [L] - simply goes to /folder/subfolder/static_page_folder
RewriteRule ^/static_page_folder2(.*) /static/page/folder/not/in/root/folder$1 [L] - same as above except to a different folder than the document root
RewriteRule ^/(.*) http://www.bar.com:8080/zope_folder/$1 [P,L] - proxy passes to your zope site all requests not explicitly stated in the static pages rewrite rules.

Save your file and restart the Apache server.

Step 2

Now go to your management screen for zope.
Go inside the /zope_folder.

Warning: Be careful when adding SiteRoots. You might be locked out if configured wrongly.

Add a SiteRoot object.
Edit the contents.

Title
Base
Path
Be careful in the Base part as an extra "/" can cause error in your site.
It will really depend on your links.

Step 3

Great! Now you have RewriteRules and a SiteRoot!
Close your browser and Open a new one.
If you don't, authentication glitches may confuse you.

Step 4

Now try: http://www.foo.com.
You should now see your zope site that is located in http://www.bar.com:8080/zope_folder.
The links should now appear as http://www.foo.com/folder.
/folder is the folder under /zope_folder.

If you get locked out

As Trevor Toenjes ([email protected]) has reminded me to add here:
If you get locked out, you can disable SiteRoot by adding _SUPPRESS_SITEROOT.
Example:
http://www.foo.com/_SUPPRESS_SITEROOT/manage

Another option is to ftp into Zope and delete SiteRoot.
Good Luck!

Summary

That's it! Good luck!

And hope SiteRoot doesn't lock you out!

Acknowledgements

There are parts here that are modified from Anser's How-To: Using Apache with ZServer (NOT Zope.cgi)