>>>>> "Jean-Michel" == Jean-Michel Hiver <[EMAIL PROTECTED]> writes:

Jean-Michel> That'd make our system administrator go nuts (and I would
Jean-Michel> understand...), which is why I'd like to keep the caching code within
Jean-Michel> the software so that we simply need to do a CVS up and maybe change
Jean-Michel> Apache::Registry to Apache::CachedRegistry or something... 

Well, with the right tools, it's actually pretty sane.  I'm currently
running both stonehenge.com and geekcruises.com on the same pool
of server instances (front and back).  I describe in my article at
<http://www.stonehenge.com/merlyn/LinuxMag/col38.html> about how nearly
everything on my site is driven by Template Toolkit, both at site
generation time and for dynamic pages at runtime.

Every virtual server is actually a simple template invocation that
sets up the mod_proxy instructions for the front end, and the listening
address for the backend.  I then create the separate httpd.conf files
from that, and launch the servers.  To test the servers, I bind
a development server to a series of numbered ports for the front end
and then I can use those addresses in lieu of named-based services.

For example, the definition of www.stonehenge.com looks like:

    [* WRAPPER make_virtual_server
      name = "www.stonehenge.com" develport = 8001
      host = "www.stonehenge.com" port = 80
      backhost = "127.0.0.1" backport = 8081;
      WRAPPER pbj_filter *]
    #PJ# ## local services:
    #PJ# RewriteRule ^/icons/ - [last]
    #PJ# RewriteRule ^/tt2/images/ - [last]
    #PJ# RewriteRule ^/mindterm/$ /mindterm/index.html [last]
    #PJ# RewriteRule ^/mindterm/ - [last]

    ## local redirect:
    RewriteRule ^/cgi/go/(.*)$ $1 [redirect,last,noescape]

    ## status
    <IfModule mod_status.c>
      <Location /XXX-status>
        SetHandler server-status
      </Location>
    </IfModule>

    <IfModule mod_info.c>
      <Location /XXX-info>
        SetHandler server-info
      </Location>
    </IfModule>

    #BJ#  <IfModule mod_perl.c>
    #BJ#  <Perl>
    #BJ#  use lib "[* env.PREFIX *]/perl-lib";
    #BJ#  do "startup.pl";
    #BJ#  </Perl>
    #BJ#  </IfModule>
    #BJ#  ErrorDocument 404 /404.html
    [* END; END *]

The lines marked #PJ# and #BJ# are being noticed by my "PBJ" filter,
which uncomments lines for the "P"roxy or "B"ack-end as needed
(or for the "J"oined single-server version), so the rewrite rules
there apply only to the front and not the back.  The first
few lines tell me that I have a server named www.stonehenge.com listening
at www.stonehenge.com:80, and that it's actually a proxy through
to localhost:8081.

Inside make_virtual_server, we find:

    BLOCK make_virtual_server;
      # name = "www.stonehenge.com"
      # alias = "web.stonehenge.com w3.stonehenge.com" # if applicable
      # host = "www.stonehenge.com" # or IP
      # port = "80";
      # backhost = "127.0.0.1" # optional
      # backport = "8080" # optional
      # host_port_default = 1 for the default server for name-virtuals

      IF env.DEVEL;
        name = "127.0.0.1";
        host = "127.0.0.1";
        port = develport;
      END;

      IF kind == "B";
        RETURN UNLESS backhost;
        listen_host_port = "$backhost:$backport";
      ELSE;
        listen_host_port = "$host:$port";
      END;
      "\n## virtual server for $name from $host:$port to $backhost:$backport\n";
      IF make_virtual_server_listeners.$listen_host_port;
        "# seen # ";
      ELSE;
         make_virtual_server_listeners.$listen_host_port = 1;
      END;
      "Listen $listen_host_port\n";
      "<VirtualHost $listen_host_port";
        " _default_:*" IF host_port_default;
      ">\n";
      "  ServerName $name\n";
      "  ServerAlias $alias\n" IF alias;
      "  Port $port\n";
      "  RewriteEngine On\n"; # we always seem to need this
      content FILTER indent(2);
      IF kind == "P"; *]
      RewriteRule ^/icons/ - [last]
      RewriteMap escape int:escape
      RewriteRule ^/(-/)?(.*)$ http://[* "$backhost:$backport" *]/${escape:$2} 
[proxy,noescape]
      ProxyPassReverse / http://[* name *]:[* port *]/
      RewriteRule .* - [forbidden]
    [*
      END;
      "</VirtualHost>\n";
    END;

The "kind" here is "P" "B" and "J" as before.  The RewriteRules here
take care of the proxying forward, and the rewriting of the backend
for most self-references (like redirects and CGI.pm's self-referencing
URLs).  The backend really doesn't need to know what the front-end
address is, and therefore doesn't care that it's even in a proxy
situation.

Yes, this took some work to do.  I first prototyped it on stonehenge.com,
wrote the article about it, then got a contract at buffalo.edu to do
it better, and then took that knowledge back and rewrote stonehenge.com
again.  And when geekcruises.com came along, it was a simple step for
me to add:

    [* WRAPPER make_virtual_server
      name = "geekcruises.stonehenge.com" develport = 8005
      alias = "www.geekcruises.com geekcruises.com"
      host = "geekcruises.stonehenge.com" port = 80
      backhost = "127.0.0.1" backport = 8083;
      WRAPPER pbj_filter *]
      DocumentRoot [* env.GEEKCRUISES_ROOT *]

      <Directory [* env.GEEKCRUISES_ROOT *]>
          Options All MultiViews
          AllowOverride All
          <IfModule mod_access.c>
              Order Allow,Deny
              Allow from All
              <Files ~ "^\.|~$">
                  Order Allow,Deny
                  Deny from All
              </Files>
          </IfModule>
          <IfModule mod_dir.c>
              DirectoryIndex index.html index.htm
          </IfModule>
      </Directory>
      # Alias /icons/ [* env.PREFIX *]/htdocs/icons/
    #BJ#  <IfModule mod_perl.c>
    #BJ#  <Perl>
    #BJ#  use lib "[* env.PREFIX *]/perl-lib";
    #BJ#  </Perl>
    #BJ#  PerlPostReadRequestHandler Stonehenge::MyPostReadRequest
    #BJ#  </IfModule>

    [* END; END *]

and then they're up and running, with their own docroot.

If you want me to set this up for you, I'm available.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html

Reply via email to