You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by John ORourke <jo...@o-rourke.org> on 2007/12/03 13:28:23 UTC

dynamic config

Hi folks,

I'm sure this has cropped up in the past but I can't see anything 
obvious in the archives (regex search on the archives would be great!)

I have some apps where users want to add extra domains and I'd like to 
do it on the fly if possible - in other words, modify the ServerAlias 
list from within mod_perl.  Does anyone have any tips/pointers/archives?

thanks
John


Re: dynamic config

Posted by Adam Prime <ad...@utoronto.ca>.
I think that to truly change the ServerAlias in all your processes you 
need to restart the server, but i could very well be wrong.

However, this is something i've wanted to do too, and the way i had been 
thinking about getting around an inability to add ServerAliases in the 
short term was to set up a catch all virtual host that would use the 
requests Host header to determine what it should ultimately do with the 
request.

In the scenario i was imagining i'd have an init handler that would run 
on the catch all vhost which would stuff a handful of variables into 
pnotes.  My later phase code would then check for the existance of the 
pnotes variables, and either use them, or use it's normal route of doing 
whatever it was wanting to do.

If you were just adding additional server aliases for already set up 
sites you could just have your init handler redirect to the 'main' 
domain' of that alias or something like that.

Another option to think about anyway.

Adam



John ORourke wrote:
> Hi folks,
> 
> I'm sure this has cropped up in the past but I can't see anything 
> obvious in the archives (regex search on the archives would be great!)
> 
> I have some apps where users want to add extra domains and I'd like to 
> do it on the fly if possible - in other words, modify the ServerAlias 
> list from within mod_perl.  Does anyone have any tips/pointers/archives?
> 
> thanks
> John
> 


Re: dynamic config

Posted by Torsten Foertsch <to...@gmx.net>.
On Mon 03 Dec 2007, John ORourke wrote:
> I have some apps where users want to add extra domains and I'd like to
> do it on the fly if possible - in other words, modify the ServerAlias
> list from within mod_perl.  Does anyone have any tips/pointers/archives?

You mean you need a PerlTranslationHandler plus maybe a 
PerlMapToStorageHandler that inspect $r->hostname and add some configurations 
depending on it? Maybe Apache2::Translation can help.

Otherwise you can only edit the config file and restart apache.

Adding or modifying a ServerAlias at runtime is not possible in Perl. Even a 
PerlPostReadRequestHandler is run after the request is assigned to a vhost, 
see server/protocol.c:

    /* Get the request... */
    if (!read_request_line(r, tmp_bb)) {
        ...
        ap_get_mime_headers_core(r, tmp_bb);
    /* update what we think the virtual host is based on the headers we've
     * now read. may update status.
     */
    ap_update_vhost_from_headers(r);
    ...
    if ((access_status = ap_run_post_read_request(r))) {
    ...

read_request_line reads the GET/HEAD/POST/... line, ap_get_mime_headers_core 
reads the http headers and ap_update_vhost_from_headers switches to a name 
based vhost. Only after that the post read request phase is run. So you can't 
interfere before the request is assigned to the vhost.

Torsten