mldvx4 has asked for the wisdom of the Perl Monks concerning the following question:
I'd like to be able to split an old Apache2 configuration file into separate files one per virtual host. Would Config::ApacheFormat be the right module for that? It seems to read the configuration file in just fine, but how do I separate the VirtualHost blocks generically? And once, separate, how do I make the output something that Apache2 can tolerate?
PS. What if the value of VirtualHost (e.g. *:80, *:443) is different? I'd like the separation to occur for all vhosts, regardless of settings.
#!/usr/bin/perl use strict; use warnings; use Config::ApacheFormat; my $configfile = shift || '/dev/stdin'; my $config = Config::ApacheFormat->new( root_directive => 'ServerRoot', hash_directives => [ 'AddHandler' ], include_directives => [ 'Include', 'AccessConfig', 'ResourceConfig' ], setenv_vars => 1, fix_booleans => 1); $config->read( $configfile ); my @vhosts = $config->block( 'VirtualHost'=>'*:80' ); exit( 0 ); my $http = qq( + # Ensure that Apache listens on port 80 + Listen 80 <VirtualHost *:80> DocumentRoot "/www/example1" ServerName www.example.com # Other directives here </VirtualHost> + <VirtualHost *:80> DocumentRoot "/www/example2" ServerName www.example.org # Other directives here </VirtualHost> + );
|
|---|