Apache HTTP 服务器/mod_perl
来自 project
- 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
并让它重新加载配置。
最后,根据选择的替代配置,访问