跳转至内容

Apache HTTP 服务器/mod_perl

来自 ArchWiki
(从 Mod perl 重定向而来)

来自 项目

mod_perl 汇集了 Perl 编程语言和 Apache HTTP 服务器 的全部强大功能。您可以使用 Perl 来管理 Apache、响应网页请求等等。

安装

安装 mod_perlAUR 包。

配置

通过主 Apache 配置文件加载模块

httpd.conf
LoadModule perl_module modules/mod_perl.so

允许 Perl 为特定目录执行脚本

有两种方法可以启用 mod_perl 模块

使用虚拟主机

添加一个带有设置的虚拟主机。例如

/etc/httpd/conf/extra/httpd-vhosts.conf
<VirtualHost perlwebtest:80>
	Servername perlwebtest
	DocumentRoot /srv/http/perlwebtest
	ErrorLog /var/log/httpd/perlwebtest-error.log
	CustomLog /var/log/httpd/perlwebtest-access.log combined
	<Directory /srv/http/perlwebtest>
		AddHandler perl-script .pl
		PerlResponseHandler ModPerl::Registry
		Options +ExecCGI
		PerlOptions +ParseHeaders
		AllowOverride All
		Order allow,deny
		Allow from all
	</Directory>
</VirtualHost>

确保 /etc/httpd/conf/httpd.conf 包含已创建的虚拟主机

Include conf/extra/httpd-vhosts.conf

确保它不包含 Options Indexes FollowSymLinks!

/etc/hosts 中将 "perlwebtest" 添加为 localhost,并将 yourhostname 用作您计算机的主机名

127.0.0.1	localhost yourhostname perlwebtest

为子目录

将以下内容添加到主配置文件

/etc/httpd/conf/httpd.conf
Alias /perlwebtest/ /srv/http/perlwebtest/
<Location /perlwebtest/>
      AddHandler perl-script .pl
      AddHandler perl-script .cgi
      PerlResponseHandler ModPerl::Registry
      PerlOptions +ParseHeaders
      Options +ExecCGI
      Order allow,deny
      Allow from all
</Location>

为目录列表启用 Perl

同时创建 /etc/httpd/conf/extra/perl_module.conf

/etc/httpd/conf/extra/perl_module.conf
# Required modules: dir_module, perl_module

<IfModule dir_module>
        <IfModule perl_module>
                DirectoryIndex index.pl index.html
        </IfModule>
</IfModule>

然后在 /etc/httpd/conf/httpd.conf 中包含它

/etc/httpd/conf/httpd.conf
# Perl
Include conf/extra/perl_module.conf

尝试一下

/srv/http/perlwebtest 中创建 index.pl

#!/usr/bin/perl
print "Content-type: text/plain\n\n";
print "mod_perl now works\n";

重启 Apache 的 httpd.service 并让它重载配置。

最后,取决于您选择的替代配置,访问