如何使用 mod_perl 使 Apache 处理 .pl (Perl) 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/409686/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 17:05:57  来源:igfitidea点击:

How do I make Apache handle .pl (Perl) files, using mod_perl?

perlapachemod-perl

提问by

I'm using Apache 2. I know how to handle .pl files as "cgi-script", but mod_perl is supposedly way faster. I successfully built and installed mod_perl, but how do I change httpd.conf so that .pl files will be handled by mod_perl (and not as cgi-script)?

我正在使用 Apache 2。我知道如何将 .pl 文件作为“cgi-script”来处理,但是 mod_perl 据说要快得多。我成功构建并安装了 mod_perl,但是如何更改 httpd.conf 以便 .pl 文件将由 mod_perl 处理(而不是作为 cgi-script)?

回答by ChrisN

How to do this is described in the mod_perl documentation here. In particular, read the "Registry Scripts" section.

此处的 mod_perl 文档中描述了如何执行此操作。特别是,阅读“注册表脚本”部分。

回答by AndrewPK

The following is untested by myself and can be added to an existing vhost directive file

以下内容未经本人测试,可以添加到现有的vhost指令文件中

PerlModule ModPerl::Registry
<Files ~ "\.(pl|cgi)$">
SetHandler perl-script
PerlResponseHandler ModPerl::Registry
Options +ExecCGI
PerlSendHeader On
</Files>

and then any .pl or .cgi files in any of your directories will execute.

然后将执行任何目录中的任何 .pl 或 .cgi 文件。

How I normally do it due to security:

出于安全考虑,我通常如何做:

PerlModule ModPerl::Registry
<Directory /opt/myawesomescripts/>
SetHandler perl-script
PerlResponseHandler ModPerl::Registry
PerlOptions +ParseHeaders
Options +ExecCGI
AllowOverride None
</Directory>

The previous method will deny Directory Browsing if you need that, you should do something like this:

如果需要,前面的方法将拒绝目录浏览,您应该执行以下操作:

PerlModule ModPerl::Registry
<Directory /var/www/>
Options FollowSymLinks MultiViews ExecCGI Indexes
AddHandler perl-script .cgi .pl
PerlResponseHandler ModPerl::Registry
AllowOverride None
Order allow,deny
allow from all
</Directory>

回答by helloandre

I'm fairly certain as long as you have the module loaded, you can just add a

我很确定只要你加载了模块,你就可以添加一个

AddHandler mod_perl .pl

AddHandler mod_perl .pl