Apache-2.2
Apache 配置中的 Perl 部分不起作用
我已經通過 yum 在我的伺服器上安裝了 mod_perl 以使用 Apache 配置中的 Perl 部分。我在 CentOS 6 上執行 Apache 2.2。我通過 cpan 安裝了必要的 Perl 模組(主要是 DB2 驅動程序)。
這是腳本:
<Perl> #!/usr/bin/perl # # @File ApacheDomainHandler.pl # @Author Martin # @Created 05.01.2015 16:53:45 # use strict; use warnings; # use module use XML::Simple; use DBI; use Apache2::ServerUtil(); use Apache::PerlSections(); my $apache = Apache2::ServerUtil->server; my $database = 'dbi:DB2:XXXXXX'; my $user = 'XXXXXXXX'; my $password = 'XXXXXX'; my $schema = 'XXXX'; my $blogapiurl = 'http://localhost'; my $dbh = DBI->connect($database, $user, $password) or die "Can't connect to $database: $DBI::errstr"; my $sth = $dbh->prepare( qq{ SELECT "businessXML" from $schema."Organisations" } ) or die "Can't prepare statement: $DBI::errstr"; my $rc = $sth->execute or die "Can't execute statement: $DBI::errstr"; my $businessXML; while (($businessXML) = $sth->fetchrow()) { my $xml = XMLin($businessXML); if($xml && $xml->{website}){ my $url = URI->new($xml->{website}); if($url->host){ my $host = $url->host; my $orgId = $xml->{id}; my $vhost = qq{ <VirtualHost *:80> ServerName $host ProxyPreserveHost Off ProxyPass /assets $blogapiurl/assets ProxyPassReverse /assets $blogapiurl/assets ProxyPass / $blogapiurl/user/$orgId/ ProxyPassReverse / $blogapiurl/user/$orgId/ </VirtualHost> }; //$apache->add_config($vhost); $apache->add_config([$vhost]); } } } # check for problems which may have terminated the fetch early warn $DBI::errstr if $DBI::err; $sth->finish; $dbh->disconnect; print STDERR Apache::PerlSections->dump( ); </Perl>
我認為伺服器根本沒有使用腳本。轉儲在 error_log 中沒有給我任何資訊。如何檢查 Apache 是否真的在使用我的腳本?
我想通了……你不能用
add_config()
. 相反,首先創建一個包含每一行的數組,然後將此數組添加到配置中:my $vhost = [ "<VirtualHost *:80>", "ServerName $host", "ProxyPreserveHost Off", "ProxyPass /assets $blogapiurl/assets", "ProxyPassReverse /assets $blogapiurl/assets", "ProxyPass / $blogapiurl/user/$orgId/", "ProxyPassReverse / $blogapiurl/user/$orgId/", "</VirtualHost>" ]; $apache->add_config($vhost);