perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mathieu <jon...@club-internet.fr>
Subject Re: Generating vhost config dynamically with DBI ?
Date Mon, 05 Aug 2002 23:38:01 GMT
sk@lists.randomfx.net wrote:

> Hi,
>
>         Is there a way to have apache dynamically fetch the vhost config
> from an SQL database?  I would like to avoid restarting apache as I may be
> adding/deleting many vhosts each day.
>
>         I know I can generate apache configs using mod_perl but i need to
> restart apache to get these changes seen.
>
>         Any hope for me?
>
>         Regards,
>
> --
> Sean Kelly

Hi,
    some weeks ago I posted to have ideas on the same problem.
For now I found two solutions :
    - use perl sections in the httpd.conf and fetch data from the database,
then use a PerlChildInitHandler to refresh the vhost lists.
    - use one vh which will intercept all requests for requested
virtualhosts.

For the first solution I manage to add vhost on the fly but cannot find the
way to delete them and have the configuration refreshed.
I didn't went too deep in the problem but I couldn't managed to update my
configuration and as I'm not very familiar with mod_perl
hacking I just dropped the idea for another one.

The second solution is the one I'm actually working on for a project. I only
have one virtual host declared in my apache configuration.
Say :
<VirtualHost _default_>
  ServerName www.dynvh.com
   ErrorLog ..
   CustomLog ...
  SetHandler perl-script
  <Location "/">
    PerlHandler MainHandler
  </Location>
</VirtualHost>

All the dynamic virtual host that I want to manage point to the Ip of this
virtual host.
So all the work is going to be done by the MainHandler that will analyse the
client request.

This is for the client part.
On the other side, I have an administration interface that permits me to
declare domains, sub-domains, domain alias, subdomain aliases,
which are stored in a database. Based on the information stored in the
database I generate a structure a bit like the one generated through
the perl-sections, with all the domains, subdomains, aliases, etc ... This
cached structure being accessible by the MainHandler.

So when a client request  www.mydynvh1.com, the request is going to be taken
care of by MainHandler which knows through the
cache structure the declared vhost on the system. The vhost requested by the
client can be retrieved through the $r->hostname (which
checks the $r->header_in('Host') of the client, its the following format
www.mydynvh1.com and if the port is specified www.mydynvh1.com:8080).

So now if the vh is declared I can process the rest of the request through
other handlers or redirect the client to an error page.

I prefer the second solution as from what I want to do I have more control on
all the processing and I didn't manage to do what I wanted
with the first solution. Maybe there are other ones which I'm not aware of,
but be glad to here of.

I hope this will help you, I will really appreciate any critiques and
feedback on my solution and what can be ameliorated.

Regards,
    Mathieu



Mime
View raw message