前言
服务器上有一个Perl的CGI脚本访问总是报错500
正文
对于一个CGI脚本,需要进行如下配置:
- 加载模块
LoadModule cgid_module modules/mod_cgid.so #当Apache使用共享模块支持构建的
LoadModule cgi_module modules/mod_cgi.so #当在Windows上,或者使用像prefork这样的非线程MPM
- 配置别名(路径配置)
ScriptAlias "/cgi-bin/" "/usr/local/apache2/cgi-bin/"
- 添加处理器(使apache识别脚本后缀)
AddHandler cgi-script .cgi .pl
- 使CGI允许执行
<Directory "/usr/local/apache2/htdocs/somedir">
Options +ExecCGI
</Directory>
我们可以写一个CGI demo:first.pl
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello, World.";
访问如下地址以验证是否成功:
http://www.example.com/cgi-bin/first.pl