You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Andrew Ho <an...@tellme.com> on 2003/03/06 00:30:22 UTC

Transparent front-end proxying for many VirtualHosts

Hello,

I've looked through the mod_rewrite and Guide documentation and can't seem
find an answer for this, but feel free to point me at TFM to R if I just
missed it.

I have an Apache with many VirtualHosts, and I want to setup proxying so
that a lightweight frontend Apache with mod_rewrite/mod_proxy proxies
Apache::Registry script requests back to a heavyweight backend Apache
running on a localhost-only port.

I want to simplify my configuration in two ways. I'd prefer not to
maintain two sets of VirtualHost configuration data, and I'd like it if
the block that proxies .pl files to the backend proxy not be replicated
per VirtualHost.

The conceptual behavior I want, is for <FilesMatch "\.pl$"> to be proxied
by the backend server, and everything else by the frontend. I've tried
many combinations which don't work, which I can post if it's relevant...
it seems that having a map outside of <VirtualHost> blocks doesn't work (I
get a GET /real/path/on/filesystem/to/foo.pl HTTP/1.0 on the backend) and
that requests with path_info don't work.

Does anybody have a pointer to a setup that looks like this?

Thanks in advance!

Humbly,

Andrew

----------------------------------------------------------------------
Andrew Ho               http://www.tellme.com/       andrew@tellme.com
Engineer                    1-800-555-TELL          Voice 650-930-9062
Tellme Networks, Inc.                                 Fax 650-930-9101
----------------------------------------------------------------------


Re: Transparent front-end proxying for many VirtualHosts

Posted by Ask Bjoern Hansen <as...@develooper.com>.
On Wed, 5 Mar 2003, Andrew Ho wrote:

> I want to simplify my configuration in two ways. I'd prefer not to
> maintain two sets of VirtualHost configuration data, and I'd like it if
> the block that proxies .pl files to the backend proxy not be replicated
> per VirtualHost.

With the details you provided the best advice, as others have given,
is mod_macro or making the httpd.conf from a template.  I usually do
the latter.

If you added more details, for example a sample httpd.conf for the
proxy and the backend it would be easier to help.

Do you use 2.0 for the proxy?
http://httpd.apache.org/docs-2.0/mod/mod_proxy.html#proxypreservehost
is often helpful.

"RewriteOptions inherit" might also help simplify your configuration.

> The conceptual behavior I want, is for <FilesMatch "\.pl$"> to be proxied
> by the backend server, and everything else by the frontend. I've tried
> many combinations which don't work, which I can post if it's relevant...

Please do.  :-)

[...]
> Does anybody have a pointer to a setup that looks like this?

Maybe I am completely misunderstanding the problem, but a guess
would be something like the following in the proxy:

ProxyPreserveHost yes
RewriteRule ^/(.*\.pl) http://localhost:1234/$1 [P]

<virtualhost _default_>
  ServerName foo.example.com
  RewriteEngine  on
  RewriteOptions inherit
</virtualhost>

<virtualhost _default_>
...


 - ask

-- 
ask bjoern hansen, http://www.askbjoernhansen.com/ !try; do();

Re: Transparent front-end proxying for many VirtualHosts

Posted by Perrin Harkins <pe...@elem.com>.
On Wed, 2003-03-05 at 18:30, Andrew Ho wrote:
> I want to simplify my configuration in two ways. I'd prefer not to
> maintain two sets of VirtualHost configuration data, and I'd like it if
> the block that proxies .pl files to the backend proxy not be replicated
> per VirtualHost.

As others pointed out, mod_macro is good for this.  Personally, I tend
to solve problems like this by generating my httpd.conf with a template
and a tiny Perl script.  That allows me to do absolutely anything in it,
including looking up data from a database to use in the conf file.

- Perrin


Re: Transparent front-end proxying for many VirtualHosts

Posted by Larry Leszczynski <la...@furph.com>.
Hi Andrew -

> I want to simplify my configuration in two ways. I'd prefer not to
> maintain two sets of VirtualHost configuration data, and I'd like it
> if the block that proxies .pl files to the backend proxy not be
> replicated per VirtualHost.

Have you looked at mod_macro?  Depending on how similar your virtual hosts
are to each other, it might be useful. For example, suppose you set up
config files like so:

FrontEndMacros.cfg:

   <Macro MyVirtualHost $host $dir>
      <VirtualHost *>
         ServerName $host
         DocumentRoot $dir
         <LocationMatch "\.pl$">
            RewriteRule ...rule to proxy to backend...
         </LocationMatch>
         ...other frontend config stuff...
      </VirtualHost>
   </Macro>

BackEndMacros.cfg:

   <Macro MyVirtualHost $host $dir>
      <VirtualHost *>
         ServerName $host
         DocumentRoot $dir
         ...other backend config stuff...
      </VirtualHost>
   </Macro>

MyVirtualHosts.cfg:

   Use MyVirtualHost www.siteA.com /path/to/siteA/htdocs
   Use MyVirtualHost www.siteB.com /path/to/siteB/htdocs
   Use MyVirtualHost www.siteC.com /path/to/siteC/htdocs

httpd.conf for frontend:

   Listen 1.2.3.4:80
   NameVirtualHost *
   Include FrontEndMacros.cfg
   Include MyVirtualHosts.cfg

httpd.conf for backend:

   Listen 127.0.0.1:8080
   NameVirtualHost *
   Include BackEndMacros.cfg
   Include MyVirtualHosts.cfg


This could let you maintain just one included file that defined the list
of virtual hosts, and even though the proxying block would be replicated
for each frontend host, at least you wouldn't have to do that manually.  
You could probaly even combine the macro definitions in FrontEndMacros.cfg
and BackEndMacros.cfg with some appropriately placed <IfDefine> blocks.

More mod_macro info is at:
   http://www.coelho.net/mod_macro/
(It says it's an Apache 2 module but version 1.1.2 works with Apache
1.3.X)


HTH,
Larry Leszczynski
larryl@furph.com