CGI(Common Gateway Interface)

要启动CGI只需在apache的主配置文件/etc/httpd/conf/httpd.conf中配置ScriptAlias 指令即可。

ScriptAlias /cgi-bin/ /var/www/cgi-bin/

真正的脚本要放到/var/www/cgi-bin/目录下,脚步要想执行得有执行权限(这正是cgi的缺点,是一种不安全的机制),且要求脚本以 Content-type: text/html和一个空白行开始。所以可以用          echo -e Content-type: text/html\n\n 。比如:

vi /var/www/cgi-bin/a.cgi

#!/bin/bash

#

echo -e Content-type: text/html\n\n

Bash语句。。。。。

测试:chmod +x a.cgi

在浏览器中输入http://172.16.1.1/cgi-bin/a.cgi

如果有错误可通过查看/var/log/httpd/error_log文件查看错误提示。比如执行tail -10 /var/log/httpd/error_log