Log in |
Zope/Apache Virtual HostThis document explains how I set up Zope and Apache to serve virtual hosts with separate Zope servers and databases. The example involves two virtual hosts, site1 and site2, being served from a RedHat 6.0 GNU/Linux host. As always, if I have explained something poorly or totally munged the examples, or you see something that could be made more elegant or secure, please let me know. Zope SitesThere are four Zope sites served from two databases (and two ZServer instances) on this host. The two databases are zope0 and site3. zope0 serves no public content; it simply contains within its subfolders the sites called site1 and site2. site3 has its own Zope instance and its own database. Requests for content result in the following:
FilesystemMy directory structure includes the following:
httpd.confNote: The lines ending with "\" are continued on the following line and appear in the original file on a single line. Lines 4, 12, 26 and 38 allow each site to have its own set of scripts. zope0, site2 and site2 use the same directory because they use the same Zope database and so must use the same Zope.cgi script. zope0zope0 is the database for site1 and site2. It has no public content of its own. Its only meaningful content is the management interface. 1 <VirtualHost 192.168.1.1> 2 ServerName zope0.mydomain.com 3 # ...other Apache stuff... 4 ScriptAlias /cgi-bin/ /home/httpd/cgi-bin/zope0/ 5 RewriteEngine on 6 RewriteCond %{HTTP:Authorization} ^(.*) 7 RewriteRule ^(.*) /home/httpd/cgi-bin/zope0/Zope.cgi$1 \ [e=HTTP_CGI_AUTHORIZATION:%1,t=application/x-httpd-cgi,l] 8 </VirtualHost> Line 7 sends all requests through the Zope.cgi script. site1site1 is mostly served by Zope. It has a few static files that are served by Apache; these requests are prefixed with "/static". 9 <VirtualHost 192.168.1.2> 10 ServerName www.site1.com 11 # ...other Apache stuff... 12 ScriptAlias /cgi-bin/ /home/httpd/cgi-bin/zope0/ 13 RewriteEngine on 14 RewriteCond %{REQUEST_URI} !^/static/ 15 RewriteCond %{HTTP:Authorization} ^(.*) 16 RewriteRule ^/Site1(.*) /home/httpd/cgi-bin/zope0/Zope.cgi/Site1$1 \ 17 [e=HTTP_CGI_AUTHORIZATION:%1,t=application/x-httpd-cgi,l] 18 RewriteCond %{REQUEST_URI} !^/static/ 19 RewriteCond %{HTTP:Authorization} ^(.*) 20 RewriteRule ^(.*) /home/httpd/cgi-bin/zope0/Zope.cgi/Site1$1 \ 21 [e=HTTP_CGI_AUTHORIZATION:%1,t=application/x-httpd-cgi,l] 22 </VirtualHost> Lines 14 and 18 prevent requests beginning with "/static" from being rewritten; they will be handled by Apache directly. There are two sets of rewrite rules so that, if a request begins with "/Site1", it will not be rewritten with a "/Site1" prepended to it. This would result in the URLs getting progressively longer as you navigate the site, with multiple "/Site1" strings added. If anyone knows of a more elegant solution to this, please let me know. site2site2 is served completely by Zope; there are no static files. 23 <VirtualHost 192.168.1.3> 24 ServerName www.site2.com 25 # ...other Apache stuff... 26 ScriptAlias /cgi-bin/ /home/httpd/cgi-bin/zope0/ 27 RewriteEngine on 28 RewriteCond %{HTTP:Authorization} ^(.*) 29 RewriteRule ^/Site2(.*) /home/httpd/cgi-bin/zope0/Zope.cgi/Site2$1 \ 30 [e=HTTP_CGI_AUTHORIZATION:%1,t=application/x-httpd-cgi,l] 31 RewriteCond %{HTTP:Authorization} ^(.*) 32 RewriteRule ^(.*) /home/httpd/cgi-bin/zope0/Zope.cgi/Site2$1 \ 33 [e=HTTP_CGI_AUTHORIZATION:%1,t=application/x-httpd-cgi,l] 34 </VirtualHost> This is very similar to the rewrite rules for site1. site3site3 has its own Zope database and its own Zope instance. It is served mostly by Apache; requests beginning with "/Objects" are passed to Zope. 35 <VirtualHost 192.168.1.4> 36 ServerName www.site3.com 37 # ...other Apache stuff... 38 ScriptAlias /cgi-bin/ /home/httpd/cgi-bin/site3/ 39 RewriteEngine on 40 RewriteCond %{HTTP:Authorization} ^(.*) 41 RewriteRule ^/Objects(.*) /home/httpd/cgi-bin/site3/Zope.cgi$1 \ 42 [e=HTTP_CGI_AUTHORIZATION:%1,t=application/x-httpd-cgi,l] 43 </VirtualHost> Line 41 points any request beginning with "/Objects" to the appropriate Zope.cgi script. Zope.cgiThere is a Zope.cgi for each database contained in the appropriate directory in /home/httpd/cgi-bin. /home/httpd/cgi-bin/zope0/Zope.cgi#!/usr/local/Zope2/pcgi/pcgi-wrapper PCGI_NAME=Main PCGI_MODULE_PATH=/usr/local/Zope2/lib/python/Main.py PCGI_PUBLISHER=/usr/local/Zope2/pcgi/pcgi_publisher.py PCGI_EXE=/usr/local/bin/python PCGI_SOCKET_FILE=/home/httpd/zope/zope0/pcgi.soc PCGI_PID_FILE=/home/httpd/zope/zope0/pcgi.pid PCGI_ERROR_LOG=/home/httpd/zope/zope0/pcgi.log PCGI_DISPLAY_ERRORS=1 BOBO_REALM=Zope INSTANCE_HOME=/home/httpd/zope/zope0 /home/httpd/cgi-bin/site3/Zope.cgi#!/usr/local/Zope2/pcgi/pcgi-wrapper PCGI_NAME=Main PCGI_MODULE_PATH=/usr/local/Zope2/lib/python/Main.py PCGI_PUBLISHER=/usr/local/Zope2/pcgi/pcgi_publisher.py PCGI_EXE=/usr/local/bin/python PCGI_SOCKET_FILE=/home/httpd/zope/site3/pcgi.soc PCGI_PID_FILE=/home/httpd/zope/site3/pcgi.pid PCGI_ERROR_LOG=/home/httpd/zope/site3/pcgi.log PCGI_DISPLAY_ERRORS=1 BOBO_REALM=Zope INSTANCE_HOME=/home/httpd/zope/site3 Database FilesThe proper database files are replicated for each site in /home/httpd/zope. In particular, each site has its own access file and database directory. $ ll /home/httpd/zope/zope0 total 680 -rw-r----- 1 www mail 19 Jun 18 13:42 access -rw-rw-r-- 1 www mail 5 Aug 12 10:51 manager.pid -rw-r--r-- 1 www mail 2791 Aug 12 10:51 pcgi.log -rw-r--r-- 1 www mail 5 Aug 12 10:51 pcgi.pid srwxrwxrwx 1 www mail 0 Aug 12 10:51 pcgi.soc= drwxr-xr-x 3 www mail 1024 Aug 12 10:51 var/ -rw-rw-r-- 1 www mail 684954 Aug 18 19:38 z2.log $ ll /home/httpd/zope/site3 total 5 -rw-r----- 1 www mail 37 Aug 13 14:28 access -rw-rw-r-- 1 www mail 5 Aug 13 14:21 manager.pid -rw-rw-r-- 1 www mail 80 Aug 13 14:21 pcgi.log -rw-r--r-- 1 www mail 5 Aug 13 14:21 pcgi.pid srwxrwxrwx 1 www mail 0 Aug 13 14:21 pcgi.soc= drwx--x--x 3 www mail 1024 Aug 13 12:06 var/ -rw-rw-r-- 1 www mail 0 Aug 13 12:06 z2.log StartupRefer to my Starting/Stopping Zope HOWTO for specific information about how I start Zope. In effect, I run these two commands as root to start up the servers: su www -c 'python /usr/local/Zope2/z2.py \ -p /home/httpd/cgi-bin/zope0/Zope.cgi \ -w "" -m "" -f 8021 -t 2 \ INSTANCE_HOME=/home/httpd/zope/zope0 \ >> /home/httpd/zope/zope0/z2.log 2>&1 &' su www -c 'python /usr/local/Zope2/z2.py \ -p /home/httpd/cgi-bin/site3/Zope.cgi \ -w "" -m "" -f 8022 -t 2 \ -Z /home/httpd/zope/site3/manager.pid \ INSTANCE_HOME=/home/httpd/zope/site3 \ >> /home/httpd/zope/site3/z2.log 2>&1 &' I use the manager (the -Z option) on site3 but not on zope0. |