Scott Gifford wrote:
Hello,

I'm working on an Apache configuration for a cluster of machines
serving a variety of virtual hosts.

New virtual hosts are provisioned by a Web application, and all
information needed to set up the virtual hosts is in a database table.
I would like my Apache to set up the virtual hosts on the fly based on
information in the tables.
Sounds intersting.


I have seen examples for generating the virtual hosts configuration
from a database when Apache starts.  That leaves me with the problem
of how the unprivileged Web application doing the provisioning can
reliably trigger a reload across an entire cluster, and also what to
do if something goes wrong so I don't end up with a whole cluster of
dead Web servers.

It seems much cleaner to me to let Apache look up the information for
a virtual host as it is needed.  Conceptually, when each request comes
in, I would like Apache to look at the Host: header, build a temporary
virtual host entry from that, and use it to service the request.  I
will use caching to make it reasonably fast.  Then the provisioning
script just writes to the database table and is done, and I can handle
any errors on a per-request basis without Apache failing to start.

I see some hooks in PerlTransHandler and PerlMapToStorageHandler that
seem like they can almost do what I want, but I don't see how to set
other virtual host parameters, like ServerAdmin
http://perl.apache.org/docs/2.0/api/Apache2/ServerRec.html#C_server_admin_

, UseCanonicalName,
etc.

I'm just starting to work on this, and I thought I would see if
anybody had tried anything similar before and had some suggestions for
what to do, or what not to do.

I have never tried this myself, but the mod_perl 2.x documentation contains some hints that leads to believe that it should be possible.
Like
http://perl.apache.org/docs/2.0/api/Apache2/ServerRec.html
http://perl.apache.org/docs/2.0/api/Apache2/ServerUtil.html
http://perl.apache.org/docs/2.0/api/Apache2/PerlSections.html
...

I would start by defining a single VirtualHost (which will thus be the default host), with a variety of configuration sections, and see if I can *modify* them on-the-fly. Assuming that the VirtualHosts which you want to configure on-the-fly have some high degree of similarity, that sounds easier to do than building a whole configuration each time from scratch.
Like
<Location /some-highly-unlikely-prefix-001>
...
</Location>
<Location /some-highly-unlikely-prefix-002>
...
</Location>
and then modify the first Location to become
<Location /some-real-one>
...
</Location>
etc..

Reply via email to