|
|

楼主 |
发表于 2005-3-15 09:06:32
|
显示全部楼层
经过我的测试,结论如下:
为了让APACHE支持CGI程序解析(不管是用C、PHP或者BASH等其他语言写的),必须设置如下:
1、Loadmodule cgi-module modules/mod-cgi.so(载入CGI解析模块)
2、Addhandler cgi-script .cgi(指定以cgi为后缀的文件作为cgi脚本处理)
3、<directory>段中添加options execcgi(添加CGI执行权限,否则客户端会提示没有权限)
4、chmod 755 *.cgi(更改cgi程序为执行权限)
当然,为了管理和习惯的问题,我们可以添加下面的命令:
ScriptAlias /cgi-bin/ "var/www/cgi-bin/"(注意,这并非必须的,仅仅是为了引用的方便而已,仅仅是一个目录的别名)
下面附上我测试用的两个程序:
第一个:使用BASH写的:
#!/bin/sh
echo Content-type:text/html
echo
echo '<html>'
echo '<head>'
echo '<title> hello,world</title>'
echo '</head>'
echo '<body>'
echo 'hello world'
echo '</body>'
echo '</html>'
第二个:使用perl写的:
#!/usr/bin/perl
print "Content-type:text/plain\n\n";
foreach $var (sort(keys(%ENV))) {
$val=$ENV{$var};
$val=~s|\n|\\n|g;
$val=~s|"|\\"|g;
print "${var}=\"${val}\"\n";
}
~
上面是我的一些体会,欢迎大家批评指正,多谢拉。 |
|