[Zope] SOLUTION: How to pass REMOTE_ADDR through Apache

Dmitry Litovchenko Dmitry Litovchenko <deadq@bkzebra.com>
Fri, 19 Jul 2002 03:31:28 +0300


Several months ago I was looking for solution how to pass REMOTE_ADDR
inside proxied environment with Apache acting as frontend. Nobody has
the solution ready and now I have one. Pretty simple but requires
adding 6 lines in def __call__ (...) of VirtualHostMonster.py (you are
using VH Monster I hope :)

A new solution has come.

Visit your ~zope/lib/python/Products/SiteAccess and change
VirtualHostMonster.py adding these lines after

def __call__(self, client, request, response=None): so it becomes

    def __call__(self, client, request, response=None):
        '''Traversing at home'''
        vh_used = 0
        stack = request['TraversalRequestNameStack']
        while 1:
            if stack and stack[-1] == 'VirtualHostBase':
                vh_used = 1
                stack.pop()
                protocol = stack.pop()
                host = stack.pop()
                if ':' in host:
                    host, port = split(host, ':')
                    request.setServerURL(protocol, host, port)
                else:
                    request.setServerURL(protocol, host)

#-------- HERE CODE BEGINS --------
            if stack and stack[-1] == "_set_":
                stack.pop()
                names = split (stack.pop(), "#")
                values = split (stack.pop(), "#")
                for ix in range (len (names)):
                    request.set (names[ix], values[ix])
#--------- HERE CODE ENDS ---------

And modify your RewriteRule in Apache virtual host so it looks as:

RewriteRule ^/(.*) http://127.0.0.1:8080/VirtualHostBase/http/www.yourhost.com:80/_set_/REMOTE_IP#PROXIED_FOR/%{REMOTE_ADDR}#%{HTTP_X_FORWARDED_FOR}/$1 [P,L]

That's it.

This RewriteRule adds two variables to Zope REQUEST: REMOTE_IP and
PROXIED_FOR which contain demanded values.

And do not forget to refresh SiteAccess product or restart whole Zope.

-- 
Sincerely,
 Dmitry                          mailto:deadq@bkzebra.com