Apache 配置中的 Perl 部分不起作用

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>

我认为服务器根本没有使用该脚本。 Dump 在 error_log 中没有提供任何信息。我​​如何检查 Apache 是否确实在使用我的脚本?

答案1

我明白了……您不能使用 添加多行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);

相关内容