1. 设置cgi目录,允许执行cgi
<Directory "/data/wwwroot/cgi-bin">
AllowOverride all
Options ExecCgi
Order allow,deny
Allow from all
</Directory>
2. 设置cgi别名
ScriptAlias /cgi-bin/ "/data/wwwroot/cgi-bin"
ScriptAlias /cgi-bin/ "/data/wwwroot/cgi-bin"
3. 设置后缀如.cgi, .pl等等,任意可以想到的
AddHandler cgi-script .cgi .pl
4. 重启apache
cgi测试页:
将以下代码保存为test.cgi,且赋予执行权限,即可查看apache是否支持cgi
#!/usr/bin/perl
print "Content-type: text/html \n\n";
foreach $var (sort(keys(%ENV))) {
$val = $ENV{$var};
$val =~ s|\n|\\n|g;
$val =~ s|"|\\"|g;
print "${var}=\"${val}\"\n";
}
print "Content-type: text/html \n\n";
foreach $var (sort(keys(%ENV))) {
$val = $ENV{$var};
$val =~ s|\n|\\n|g;
$val =~ s|"|\\"|g;
print "${var}=\"${val}\"\n";
}
转载于:https://blog.51cto.com/sa2004/457593