perlhandler を使用するために、Apache インストールで mod_perl を動作させようとしています。
この仮想ホストを使用して、ドメインのサブディレクトリで最初に試しました
<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つのコードでテストしたことです
1 つは「print」パッケージが欠落しており、もう 1 つは「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;