Apache HTTP Server/mod_perl
外观
来自 项目
- mod_perl 融合了 Perl 编程语言和 Apache HTTP Server 的全部强大功能。您可以使用 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 并让它 重新加载 配置。
最后,根据选择的替代配置,访问
- http://perlwebtest 以使用 #使用虚拟主机,或者
- https:///perlwebtest 以使用 #为子目录。