You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Eric Cholet <ch...@logilune.com> on 2000/04/10 11:12:30 UTC

front end proxy and virtual hosts

Hi,

The front-end light server, serving static requests and proxying
dynamic requests to a back-end modperl server, is well documented,
except in the case of virtual hosts. How do you do it? Specifically,
do you setup virtual hosts on the backend server? Different IPs, or
different ports? Or just a flat url space, using mod_rewrite on the
front-end to translate the urls?

The modperl guide is sadly lacking any information in this area, so
your input will be valuable.

Thanks,
--
Eric


Re: front end proxy and virtual hosts

Posted by Vivek Khera <kh...@kciLink.com>.
>>>>> "EC" == Eric Cholet <ch...@logilune.com> writes:

EC> do you setup virtual hosts on the backend server? Different IPs, or
EC> different ports? Or just a flat url space, using mod_rewrite on the
EC> front-end to translate the urls?

I think I posted this example earlier.  This is just a snippet of the
relevant portions of the front/back end virtual configs.  It is not a
cookie-cutter example!

Basically, I use unique port number virtuals on the back-ends (so I
can redirect to localhost:XXXX bypassing some networking cruft) and
name-based virtuals on the front end, though any technique on the
front end will do.

I set "Port 80" on the back-end so that any redirects don't get sent
directly to the back-end.  Sometimes I also bind tightly to address
127.0.0.1 to prevent any outside connections when the two are on the
same box.

Stas, feel free to incorporate this example.

front end:

<VirtualHost 204.117.82.12>
  ServerName www.morebusiness.com
  ServerAlias morebusiness.com
  RewriteEngine On
  RewriteOptions 'inherit'
  # handle GIF and JPG images directly
  RewriteRule \.(gif|jpg|png|css|txt|cgi)$ - [last]
  RewriteRule ^/cgi-bin - [last]
  # pass off everything but images to the heavy-weight server via proxy
  RewriteRule ^/(.*)$ http://localhost:4077/$1 [proxy]

  Alias /_homepage /web/morebusiness/docs/_homepage-default
  Alias /_pageparts /web/morebusiness/docs/_pageparts-default

</VirtualHost>

<VirtualHost 204.117.82.12>
  ServerName govcon.morebusiness.com
  RewriteEngine On
  RewriteOptions 'inherit'
  # handle GIF and JPG images directly
  RewriteRule \.(gif|jpg|png|css|txt|cgi)$ - [last]
  RewriteRule ^/cgi-bin - [last]
  # pass off everything but images to the heavy-weight server via proxy
  RewriteRule ^/(.*)$ http://localhost:4078/$1 [proxy]

  Alias /_homepage /web/morebusiness/docs/_homepage-govcon
  Alias /_pageparts /web/morebusiness/docs/_pageparts-govcon

</VirtualHost>

back-end:

Port 80

Listen 4077
<VirtualHost localhost:4077>
  ServerName www.morebusiness.com
  Port 80
  DirectoryIndex index.brc index.ibrc index.shtml index.html

  ###########
  #
  # Get "real" remote IP address from Proxy and set it as our connection's
  # IP address so logging, etc., use that IP address.  Uses mod_perl handler.
  # For some reason, must be set per-virtual host.
  #
  ###########

  PerlPostReadRequestHandler My::ProxyRemoteAddr

  Alias /_homepage /web/morebusiness/docs/_homepage-default
  Alias /_pageparts /web/morebusiness/docs/_pageparts-default

</VirtualHost>

Listen 4078
<VirtualHost localhost:4078>
  ServerName govcon.morebusiness.com
  Port 80

  DirectoryIndex index.brc index.ibrc index.shtml index.html

  PerlPostReadRequestHandler My::ProxyRemoteAddr

  Alias /_homepage /web/morebusiness/docs/_homepage-govcon
  Alias /_pageparts /web/morebusiness/docs/_pageparts-govcon

</VirtualHost>


Re: front end proxy and virtual hosts

Posted by Vivek Khera <kh...@kciLink.com>.
>>>>> "ABH" == Ask Bjoern Hansen <as...@valueclick.com> writes:

ABH> mod_alias does - (except for ScriptAlias which is not really relevant on

Duh.  Ya know, sometimes you stare and stare and stare and it doesn't
come to you.  I don't even need mod_alias at all...

Thanks!


Re: front end proxy and virtual hosts

Posted by Ask Bjoern Hansen <as...@valueclick.com>.
On Wed, 12 Apr 2000, Vivek Khera wrote:

[...]
> Has this bitten anyone else?  Stas, I think you should mention this in
> the guide somehow as something to watch out for when using the proxy
> front-end.  The Rewrite rules are ignored when an Alias expands the
> URI, or so it seems from where I sit.

They're both Trans handlers in the normal case. So if mod_alias runs first
and matches it will return OK and mod_rewrite won't see the request.
 
So it shouldn't be a surprise. :)

I think the advice to give is to not mix them. mod_rewrite does everything
mod_alias does - (except for ScriptAlias which is not really relevant on
this list anyway) - so if you need mod_rewrite for a set of urls, use it
exclusively.


 - ask

-- 
ask bjoern hansen - <http://www.netcetera.dk/~ask/>
more than 70M impressions per day, <http://valueclick.com>


Re: front end proxy and virtual hosts

Posted by Vivek Khera <kh...@kciLink.com>.
I just ran into a bit of a conflict with Alias and Rewrite on my front
end.

Given that I have multiple virtual hosts serving up the same content
using a slightly different set of graphics and templates, the easy way
is to "Alias /_pageparts /real/page/parts/directory" and make the
alias different for each virtual host.  Then every document refers to
/_pageparts/XXX.yyy for the component it wants, and the proper one
based on the virtual host is used.

Something like this:

<VirtualHost 204.117.82.12>
  ServerName next.morebusiness.com
  RewriteEngine On
  RewriteOptions 'inherit'
  # handle GIF and JPG images directly
  RewriteRule \.(gif|jpg|png|css|txt|cgi)$ - [last]
  RewriteRule ^/cgi-bin - [last]
  # pass off everything but images to the heavy-weight server via proxy
  RewriteRule ^/(.*)$ http://localhost:4079/$1 [proxy]

  DocumentRoot /web/morebusiness/nextdocs

  Alias /_pageparts /web/morebusiness/nextdocs/_pageparts-default

</VirtualHost>

and on the back-end

Listen 4079
<VirtualHost localhost:4079>
  ServerName next.morebusiness.com
  Port 80

  DocumentRoot /web/morebusiness/nextdocs

  DirectoryIndex index.brc index.shtml index.html

  Alias /_pageparts /web/morebusiness/nextdocs/_pageparts-default
</VirtualHost>

One of the objects inside _pageparts-default is PAGEFOOT.shtml.  If I
do a 

lynx -source 'http://next.morebusiness.com/_pageparts-default/PAGEFOOT.shtml'

The page comes across fine.  If I do

lynx -source 'http://next.morebusiness.com/_pageparts/PAGEFOOT.shtml'

I get the page dumped raw.  That is, the SSI constructs are ignored.

If I enable .shtml files to be server-parsed on the front-end server,
then both return the processed result.  This is my work-around.

This leads me to believe that the Rewrite engine is ignored when an
Alias kicks in, otherwise the *.shtml files would be bounced back to
the back-end server where they get properly expanded.  Normally, this
is ok for me since everything else in the aliased directory is an
image which I want the front end to handle.

Has this bitten anyone else?  Stas, I think you should mention this in
the guide somehow as something to watch out for when using the proxy
front-end.  The Rewrite rules are ignored when an Alias expands the
URI, or so it seems from where I sit.

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Vivek Khera, Ph.D.                Khera Communications, Inc.
Internet: khera@kciLink.com       Rockville, MD       +1-301-545-6996
PGP & MIME spoken here            http://www.kciLink.com/home/khera/

Re: front end proxy and virtual hosts

Posted by Tom Mornini <tm...@infomania.com>.
On Mon, 10 Apr 2000, Eric Cholet wrote:

> The front-end light server, serving static requests and proxying
> dynamic requests to a back-end modperl server, is well documented,
> except in the case of virtual hosts. How do you do it? Specifically,
> do you setup virtual hosts on the backend server? Different IPs, or
> different ports? Or just a flat url space, using mod_rewrite on the
> front-end to translate the urls?

I use static IP's and virtualhosts on the front-ends (we're investigating
using our Foundry ServerIron load balancer to rewrite the HTTP headers to
allow for name-based virtual servers on the front-ends).

mod_rewrite handles proxying the dynamic requests and apparently mod_proxy
automatically adds the correct headers for name-based virtual hosts on the
back end.

This all takes a while to setup, but it works flawlessly once it is done.

-- 
-- Tom Mornini
-- InfoMania Printing and Prepress


Re: front end proxy and virtual hosts

Posted by Matt Carothers <ma...@telepath.com>.

On Mon, 10 Apr 2000, Eric Cholet wrote:

> The front-end light server, serving static requests and proxying
> dynamic requests to a back-end modperl server, is well documented,
> except in the case of virtual hosts. How do you do it?

On the front end:

<VirtualHost www.customer.com>
	DocumentRoot /vhosts/customer
	ProxyPass        /perl/ http://localhost/customer/perl/
	ProxyPassReverse /perl/ http://localhost/customer/perl/
</VirtualHost>

On the back end:

DocumentRoot /vhosts
BindAddress 127.0.0.1

<Directory /vhosts/*/perl>
	SetHandler perl-script
	PerlHandler Apache::Registry # Or whatever
	PerlSendHeader  On
	Options         +ExecCGI
</Directory>

- Matt


Re: front end proxy and virtual hosts

Posted by Ask Bjoern Hansen <as...@valueclick.com>.
On Mon, 10 Apr 2000, Eric Cholet wrote:

Port based backend servers is the easiest.

Use

Port 80
Listen 127.0.0.1:8088 (or whatever)
Listen 127.0.0.1:8089 ...

in your backend setup to make sure it never reveals the real port and only
listens on the loopback interface (if that's what you want).

Then the frontend can be setup in any way you like and proxy the requests
to the appropiate port on the backend.


 - ask

-- 
ask bjoern hansen - <http://www.netcetera.dk/~ask/>
more than 70M impressions per day, <http://valueclick.com>