You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Ryan Gies <ry...@livesite.net> on 2008/03/28 16:47:10 UTC
Re: Virtual host with mod_perl (off-topic)
Ahem, sorry folks about the HTML email
Ryan Gies wrote:
> I'm curious, how would this be possible with mod_perl? The below will
> fail as:
>
> $r->add_config() has failed: <VirtualHost not allowed here
>
> and when $r->add_config is changed to $r->server->add_config it will
> fail as:
>
> Can't run '$s->add_config' after server startup
>
>
> In /etc/hosts
>
> 127.0.0.1 local.example.com
>
> In httpd.conf
>
> PerlInitHandler Apache::Handlers::MyInitHandler
>
> In Apache/Handlers/MyInitHandler.pm:
>
> package Apache::Handlers::MyInitHandler;
> use strict;
> our $VERSION = 0;
>
> use Apache2::RequestUtil ();
> use Apache2::Const -compile => qw(DECLINED);
>
> sub handler {
> my $r = shift;
> $r->add_config([
> '<VirtualHost *:80>',
> 'ServerName local.example.com',
> 'DocumentRoot /var/www/example.com/htdocs',
> '<Directory /var/www/example.com/htdocs>',
> 'Order allow,deny',
> 'Allow from all',
> 'AllowOverride None',
> 'Options None',
> '</Directory>',
> '</VirtualHost>',
> ]);
> Apache2::Const::DECLINED;
> }
>
> 1;
>
>
> Perrin Harkins wrote:
>> On Fri, Mar 28, 2008 at 8:30 AM, Valerio <va...@gmail.com> wrote:
>>
>>> Instead I need a solution that allow adding a vhost to the database
>>> without need of restarting apache.
>>>
>>
>> This is not usually done with mod_perl because there are
>> lighter-weight solutions available. There's some info on vhosts with
>> mod_rewrite and mod_vhost_alias here:
>> http://httpd.apache.org/docs/2.0/vhosts/mass.html
>>
>> You can find apache modules built specifically for dynamically pulling
>> vhosts from a database here:
>> http://modules.apache.org/
>>
>> You certainly could do this from mod_perl, but I wouldn't.
>>
>> - Perrin
>>