Apache mod_rewrite/mod_proxy question

Chuck Bearden cbearden at rice.edu
Fri Mar 29 14:45:17 EST 2002


Here is a Friday afternoon technical poser.

The Setup:
----------
There's a technique of running multiple instances of Apache--one is a
lightweight front-end to serve static pages, and others loaded with e.g.
mod_perl or PHP for handling only those requests requiring their
services.  The front-end uses a simple combination of rewrites and
passive reverse proxying to forward, say, PHP requests to the
PHP-enabled Apache running on a different port, and for sending the
replies back to the user.  The idea is that the Apache processes with
larger memory & CPU requirements only get invoked when needed.  It's
documented in Stas Bekman's mod_perl Guide, for instance:

  http://perl.apache.org/guide/

Here's a sample config snippet for the lightweight Apache, forwarding
all PHP requests to a PHP-enabled Apache listening on port 8010 of
the same machine:

  <IfModule mod_rewrite.c>
    RewriteEngine On

    # rewrite to PHP server
    RewriteCond %{SCRIPT_FILENAME} .php$
    RewriteRule /(.*)$ http://localhost:8010/$1 [P]
  </IfModule>

  #
  # Proxy Server directives. Uncomment the following lines to
  # enable the proxy server:
  #
  <IfModule mod_proxy.c>
    ProxyRequests Off
    ProxyPassReverse / http://localhost:8010/
  </IfModule>

I gave this a try--works like a charm.  I thought I'd have one
PHP-enabled Apache, a mod_perl-enabled Apache (e.g. for XML via
AxKit), and all would be cool.

The Problem:
------------
My PHP application displays its output differently depending on
the IP address of the requesting browser, which it checks as the CGI
environment variables ('$HTTP_SERVER_VARS[REMOTE_ADDR]' in PHP).
When requests are proxied to the PHP server from the Apache front-end,
it sees the remote address as 127.0.0.1 (localhost).

Is there a way to pass the CGI environment as the front-end sees it
to a back-end mod_perl or PHP server?  Or is this a big weakness of
such a setup?

Thanks,
Chuck
======================================================================
 Chuck Bearden   Library Systems Programmer/Analyst   Rice University
 cbearden at rice.edu           713.348.3634          713.348.5862 (fax)
======================================================================






More information about the Web4lib mailing list