[Zope] Virtual Hosts with Apache+Zope

Edin Dizdarevic edin@ipo.de
Tue, 7 Dec 1999 12:51:15 +0100


Hello there!

Really nice thing our Zope. After solving some problems I would like to bring a
small contribution. I send You this document and You must decide if the content
is interessting enough for publishing it. 

Well:

We use a German Linux distribution SuSE 6.2 with Apache 1.3.6. We use Zope
2.0.1 under it to serve our dynamic content and take advantage of beatiful Zope
products like ZCatalog, Squishdot, TinyTable and so on. The machine is a Dual
Celeron 400 on a Abit BP6-Board, software RAID 1 and 128M. The problem was to
serve severe domains, some Content from Zope and some CGI stuff from Apache. 
No further instances of Apache or Zope are to run.

First of all you have to set the aliasing - means one network device speaking
to 3 or 4 IP numbers. After setting the first IP number you can add further
IPīs with an ifconfig call put at the end of the /etc/rc.d/network file, which
after that is looking like this:

#                                                                               
#Von Edin angepasst um aliasing zu erweitern                                    
#                                                                               
ifconfig eth0:0 192.168.1.136 broadcast 192.168.1.255 netmask 255.255.255.0     
ifconfig eth0:1 192.168.1.137 broadcast 192.168.1.255 netmask 255.255.255.0     
ifconfig eth0:2 192.168.1.138 broadcast 192.168.1.255 netmask 255.255.255.0     
ifconfig eth0:3 192.168.1.139 broadcast 192.168.1.255 netmask 255.255.255.0     

after that you should run ifconfig and get something like this:

root@guzzi:/home/edin > ifconfig 
eth0      Link encap:Ethernet  HWaddr 00:10:5A:71:E4:CE  
inet addr:192.168.1.135  Bcast:192.168.1.255  Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:93393 errors:0 dropped:0 overruns:0 frame:0
TX packets:50357 errors:0 dropped:0 overruns:0 carrier:0
collisions:26199 txqueuelen:100 
Interrupt:10 Base address:0xd400 

eth0:0    Link encap:Ethernet  HWaddr 00:10:5A:71:E4:CE  
inet addr:192.168.1.136  Bcast:192.168.1.255  Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
Interrupt:10 Base address:0xd400 

eth0:1    Link encap:Ethernet  HWaddr 00:10:5A:71:E4:CE  
inet addr:192.168.1.137  Bcast:192.168.1.255  Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
Interrupt:10 Base address:0xd400 

eth0:2    Link encap:Ethernet  HWaddr 00:10:5A:71:E4:CE  
inet addr:192.168.1.138  Bcast:192.168.1.255  Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
Interrupt:10 Base address:0xd400 

eth0:3    Link encap:Ethernet  HWaddr 00:10:5A:71:E4:CE  
inet addr:192.168.1.139  Bcast:192.168.1.255  Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
Interrupt:10 Base address:0xd400 

lo        Link encap:Local Loopback  
inet addr:127.0.0.1  Mask:255.0.0.0
UP LOOPBACK RUNNING  MTU:3924  Metric:1
RX packets:28 errors:0 dropped:0 overruns:0 frame:0
TX packets:28 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0 


This was the easy part. I will not explain how to set the RAID system. Not
here - bit if someone wants to know how to manage that I will be glad to help. 


We have several WWW-Servers which we want to put on one Zope server. In
addition we want to install Minivend Online-Shop-System, so we definetly need
Apache. 

Next, I had to reconfigure Apache with all that rewrite rules and
stuff. So this is what I put in my /etc/httpd/httpd.conf: 

This is what you have to do if you have SuSE. I donīt know about RedHat. The
problem is  "Options +ExecCGI"-line. There is another Tip/HOWTO-Document
explaining the solution. This is working.  

<Directory "/usr/local/httpd/cgi-bin">
AllowOverride None
Options +ExecCGI
Order allow,deny
Allow from all
</Directory>

This is the interesting part:

<VirtualHost 192.168.1.136>
ServerName site1.intern.de
DocumentRoot /usr/local/httpd/htdocs/site1/
ScriptAlias /cgi-bin/ /usr/local/httpd/cgi-bin/site1/
RewriteEngine on
RewriteLog /var/log/rewrite.log
RewriteLogLevel 0
RewriteCond %{HTTP:Authorisation} ^(.*)
RewriteRule ^(.*)  /usr/local/httpd/cgi-bin/site1/Zope.cgi/$1 \
[e=HTTP_CGI_AUTHORIZATION:%1,t=application/x-httpd-cgi,l] </VirtualHost>

<VirtualHost 192.168.1.137>
ServerName site2.intern.de
DocumentRoot /usr/local/httpd/htdocs/site2/
ScriptAlias /cgi-bin/ /usr/local/httpd/cgi-bin/site2/
RewriteEngine on
RewriteLog /var/log/rewrite.log
RewriteLogLevel 0
RewriteCond %{HTTP:Authorisation} ^(.*)
RewriteRule ^(.*) /usr/local/httpd/cgi-bin/site2/Zope.cgi/$1 \
[e=HTTP_CGI_AUTHORIZATION:%1,t=application/x-httpd-cgi,l]
</VirtualHost>

<VirtualHost 192.168.1.138>
ServerName site3.intern.de
DocumentRoot /usr/local/httpd/htdocs/site3/
ScriptAlias /cgi-bin/ /usr/local/httpd/cgi-bin/site3/
RewriteEngine on
RewriteLog /var/log/rewrite.log
RewriteLogLevel 0
RewriteCond %{HTTP:Authorisation} ^(.*)
RewriteRule ^(.*) /usr/local/httpd/cgi-bin/site3/Zope.cgi/$1 \
[e=HTTP_CGI_AUTHORIZATION:%1,t=application/x-httpd-cgi,l] 
</VirtualHost>

All the last lines must be one, of course.


We almost made it. The problem now is to redirect the calls comming from
Apache. There is probably another way with Rewrite-Rules but I found this one
quite comfortable and I learned something more about Zope's variables and how
to handle them. No matter what you type, you always get the root index_html.
That's not the right thing. I want people if they type www.site1.de to gho
directly to Zope's subfolder /site1. With few ifs you are the winner. Try
putting this in your index_html:


<dtml-var standard_html_header>

<dtml-if "SERVER_URL=='http://site1.intern.de'">
 <dtml-with site1>
         <dtml-call "RESPONSE.redirect('/site1/index_html')">    
 </dtml-with>
</dtml-if>

<dtml-if "SERVER_URL=='http://site2.intern.de'">
 <dtml-with site2>
         <dtml-call "RESPONSE.redirect('/site2/index_html')">    
 </dtml-with>
</dtml-if>

<dtml-if "SERVER_URL=='http://site3.intern.de'">
 <dtml-with site3>
         <dtml-call "RESPONSE.redirect('/site3/index_html')">    
 </dtml-with>
</dtml-if>

<dtml-var standard_html_footer>

Thatīs it. A week for me, for all other people now 5min ;).

Have fun...

Edin Dizdarevic
edin@tfh-berlin.de
edin@ipo.de
edind@gmx.de