Answer the question
In order to leave comments, you need to log in
How to write a regular expression in perl?
Hi everybody!
I recently started learning perl, so don't butt too hard, as it's still a complete noob.
And so, the crux of the matter. There is a certain apache config file httpd.conf.
The design is, as it were, standard under Centos:
<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 [email protected]
ScriptAlias /cgi-bin/ /var/www/someuser/data/www/somedomain.com/cgi-bin/
</VirtualHost>
Answer the question
In order to leave comments, you need to log in
You can use a similar option.
The config is like this:
<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
[email protected]
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
[email protected]
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
[email protected]
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 => '[email protected]' } )
}igse;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question