I am trying to configure virtual hosts dynamically in mod_perl2.

I have a startup file which sets up an 'application' based on my own framework. Part of that inflation creates a number of virtual hosts.

I have been trying the following:

------------------------- In httpd.conf: PerlConfigRequire /path/startup.pl ------------------------- In startup.pl: .... my $config = <<VHOST <VirtualHost 127.0.0.1> # Config </VirtualHost> VHOST Apache2::Server->server->add_config([split /\n/ $config]); -------------------------

When I tried with PerlRequire or PerlPostConfigRequire, adding the virtual host would give me a segfault.

With PerlConfigRequire, it runs fine, but if I do:

  @vhosts = Apache2::Directive::conftree->lookup("VirtualHost")

it doesn't find any virtual hosts.

I want to keep the line in httpd.conf as simple as possible. How should I go about doing this?

I could use PerlSections, but how?

<Perl> my $config = do 'startup.pl'; #parse config into @vhosts foreach my $vhost (@vhosts) { $VirtualHost{$vhost}=>$config->{$vhost} } </Perl>

Or should I use something like:

<Perl handler="startup.pl"> </Perl>

Or:

PerlOpenLogsHandler startup.pl

Help appreciated


In reply to Configuring virtual hosts dynamically with mod_perl by clinton

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.