You are not logged in Log in Join
You are here: Home » Members » dparker » Changing host names dynamically with Apache

Log in
Name

Password

 

Changing host names dynamically with Apache

A single Zope instance via Zope.cgi under Apache can be made to render pages who's contents appear to be from different hosts by altering the SERVER_URL environment variable. Situations where this capability is essential are:
  • Apache virtual hosts which share the same Zope instance.
  • Tunneling from one network to another via an HTTP proxy (e.g. from the internet to an intranet).
The trouble with trying to do these things without any "tricks" is that Zope's ZPublisher utilizes its notion of the server it's running on very extensively; if you don't takes steps to alter Zope's notion of its host, you'll end up with pages that refer to other hosts (and possibly, hosts that don't exist on the network the user is coming from).

You can remedy this by setting the SERVER_URL environment variable in Apache appropriately just prior to invoking Zope.cgi. Here are two ways to do it:

1) For Apache virtual hosts that need to point to a single Zope instance, put
SetEnv SERVER_URL http://hostname.org 
into the various VirtualHost sections you've defined at a point prior to where Zope.cgi is called (e.g. before a RewriteRule that runs Zope.cgi). hostname.org should be whatever host you want Zope to pretend it is for the virtual host in question.

2) For Apache+Zope configurations that need to be accessible on both sides of a a tunneling proxy configuration, put
SetEnvIf Remote_Addr "A\.B\.C\.D" SERVER_URL=http://hostname.org
into your Apache configuration someplace before Zope.cgi is called. A\.B\.C\.D is the IP address of the near side of your proxy server (with periods made literal, 'cause SetEnvIf uses regular expressions), and hostname.org is the name that people on the far side see your proxy server as. Note that this isn't specific to a VirtualHost configuration, though it'll work in that context as well (just put the SetEnvIf inside whatever virtual hosts you've defined).

Questions/suggestions?