【发布时间】:2012-06-08 14:30:16
【问题描述】:
我正在尝试让 mod_perl 在我的 apache 安装上工作,以便使用 perlhandler。
我首先尝试在我的域的子目录中使用此虚拟主机
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName ***.fr.cr
DocumentRoot /var/www/aw
<Directory /var/www/aw/>
AllowOverride None
Order allow,deny
allow from all
</Directory>
PerlModule test2::Rules2
alias /perl2/ /usr/lib/perl5/test2/
<Location /perl2/>
Order allow,deny
allow from all
SetHandler perl-script
PerlHandler test2::Rules2
</Location>
ErrorLog ${APACHE_LOG_DIR}/aw.error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/aw.access.log combined
</VirtualHost>
在这里,当我转到 *.fr.cr/perl2/
时它工作正常但是,当我尝试使用这个虚拟主机直接对我的域的根目录执行此操作时:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName ***.fr.cr
DocumentRoot /var/www/aw
<Directory /var/www/aw/>
AllowOverride None
Order allow,deny
allow from all
</Directory>
PerlModule aw::main
alias / /usr/lib/perl5/aw/
<Location />
Order allow,deny
allow from all
SetHandler perl-script
PerlHandler aw::main
</Location>
ErrorLog ${APACHE_LOG_DIR}/aw.error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/aw.access.log combined
</VirtualHost>
我收到错误 500,apache 日志有这一行:
Can't locate object method "content_type" via package "Apache2::RequestRec" at /usr/lib/perl5/aw/main.pm line 6.\n
奇怪的是我用 2 个代码测试了
一个缺少“print”包,一个缺少“content_type”包,第一个有“content_type”,但错误在代码后面。
我想我的虚拟主机缺少一些东西,因为它在一种情况下有效,而在另一种情况下却不能使用相同的代码。
谢谢!
编辑:代码: 不工作:
package aw::main;
use Apache2::Const qw(:common);
sub handler {
my $r = shift;
$r->content_type("text/plain");
$r->print("mod_perl rules!\n");
return OK;
}
1;
和工作:
package test2::Rules2;
use Apache2::Const qw(:common);
sub handler {
my $r = shift;
$r->content_type("text/plain");
$r->print("mod_perl rules!\n");
return OK;
}
1;
【问题讨论】:
-
最可能的结论是 aw::main 中存在一个不在 test2::Rules2 中的错误。
-
我复制/粘贴了代码。我会尝试复制文件并重命名它
-
那我是对的。首先,您的
package声明是错误的。 -
什么意思?我正在编辑我的帖子以添加代码
-
尝试添加
use Apache2::RequestRec;?不应该,但值得一试。
标签: perl apache mod-perl vhosts