Можно использовать подобный вариант.
Конфиг, допустим, такой:
<VirtualHost 222.222.222.222:81 >
ServerName somedomain.com
CustomLog /var/www/httpd-logs/somedomain.com.access.log combined
DocumentRoot /var/www/someuser/data/www/somedomain.com
ErrorLog /var/www/httpd-logs/somedomain.com.error.log
ServerAlias www.somedomain.com
SuexecUserGroup someuser somegroup
ServerAdmin webmaster@somedomain.com
ScriptAlias /cgi-bin/ /var/www/someuser/data/www/somedomain.com/cgi-bin/
</VirtualHost>
<VirtualHost 222.222.222.222:81 >
ServerName somedomain1.com
CustomLog /var/www/httpd-logs/somedomain1.com.access.log combined
DocumentRoot /var/www/someuser/data/www/somedomain1.com
ErrorLog /var/www/httpd-logs/somedomain1.com.error.log
ServerAlias www.somedomain1.com
SuexecUserGroup someuser somegroup
ServerAdmin webmaster@somedomain1.com
ScriptAlias /cgi-bin/ /var/www/someuser/data/www/somedomain1.com/cgi-bin/
</VirtualHost>
<VirtualHost 222.222.222.222:81 >
ServerName somedomain2.com
CustomLog /var/www/httpd-logs/somedomain2.com.access.log combined
DocumentRoot /var/www/someuser/data/www/somedomain2.com
ErrorLog /var/www/httpd-logs/somedomain2.com.error.log
ServerAlias www.somedomain2.com
SuexecUserGroup someuser somegroup
ServerAdmin webmaster@somedomain2.com
ScriptAlias /cgi-bin/ /var/www/someuser/data/www/somedomain2.com/cgi-bin/
</VirtualHost>
sub removeIfSomedomain($$) {
my $text = shift;
my $domain = shift;
$text = '' if $text =~ m{^\s*?ServerName\s+?$domain\s*?$}igsm;
return $text;
}
sub changeContent($$$) {
my $text = shift;
my $domain = shift;
my $new_values = shift;
return $text if $text !~ m{^\s*?ServerName\s+?$domain\s*?$}igsm;
foreach my $key ( keys %$new_values ) {
$text =~ s{^(\s*?$key\s+?).+?$}{$1$new_values->{$key}}igsm;
}
return $text;
}
my $config = ... ; # содержимое конфига
$config =~ s{(<VirtualHost[^>]*?>.*?<\/VirtualHost>)}{ removeIfSomedomain($1,'somedomain1.com') }igse;
$config =~ s{(<VirtualHost[^>]*?>.*?<\/VirtualHost>)}{
changeContent($1,'somedomain2.com', { SuexecUserGroup => 'justuser justgroup',
ServerAlias => 'www.sd2.com',
ServerAdmin => 'admin@somedomain2.com' } )
}igse;
Выхлоп:
<VirtualHost 222.222.222.222:81 >
ServerName somedomain.com
CustomLog /var/www/httpd-logs/somedomain.com.access.log combined
DocumentRoot /var/www/someuser/data/www/somedomain.com
ErrorLog /var/www/httpd-logs/somedomain.com.error.log
ServerAlias www.somedomain.com
SuexecUserGroup someuser somegroup
ServerAdmin webmaster@somedomain.com
ScriptAlias /cgi-bin/ /var/www/someuser/data/www/somedomain.com/cgi-bin/
</VirtualHost>
<VirtualHost 222.222.222.222:81 >
ServerName somedomain2.com
CustomLog /var/www/httpd-logs/somedomain2.com.access.log combined
DocumentRoot /var/www/someuser/data/www/somedomain2.com
ErrorLog /var/www/httpd-logs/somedomain2.com.error.log
ServerAlias www.sd2.com
SuexecUserGroup justuser justgroup
ServerAdmin admin@somedomain2.com
ScriptAlias /cgi-bin/ /var/www/someuser/data/www/somedomain2.com/cgi-bin/
</VirtualHost>