apache安装查看:http://blog.csdn.net/sanshuei/article/details/8146249
1. 配置/etc/httpd/httpd.conf
LoadModule cgi_module modules/mod_cgi.so # 去掉该行前面#号,确认配置中已添加cgi模块,并apache2/modules/mod_cgi.so存在
#如果没有cgi模块请查看:http://blog.csdn.net/sanshuei/article/details/8146284
ScriptAlias /cgi-bin/ "/usr/local/apache2/cgi-bin/" # 去掉该行前面#号
<Directory "/usr/local/apache2/cgi-bin">
AllowOverride None
Options +ExecCGI # None 换为 +ExecCGI 貌似可以不用加+号
Require all granted
</Directory>
AddHandler cgi-script .cgi # 去掉该行前面#号
httpd.conf配置详述请查看:
2. 配置文件修改好,重启apache
/usr/local/apache2/bin/apachectl restart
3. 使用bash编写cgi脚本时
#!/bin/sh
echo "Content-type: text/html"
echo
最后一个echo不可缺。
如果缺少时,查看logs/error_log内容有如下提示:
[root@192 apache2]# cat /usr/local/apache2/logs/error_log
[Sun Nov 04 12:15:24.027358 2012] [cgi:error] [pid 12465:tid 2949381008] [client 192.168.18.1:54405] malformed header from script 'demo.cgi': Bad header: <html>
以上为这几天配置web环境中cgi遇到问题汇总