1)配置一个默认的可当成CGI程序来执行的目录
#
# ScriptAlias: This controls which directories contain server scripts.
# ScriptAliases are essentially the same as Aliases, except that
# documents in the realname directory are treated as applications and
# run by the server when requested rather than as documents sent to the client.
# The same rules about trailing "/" apply to ScriptAlias directives as to
# Alias.
#
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
#Apache的ScriptAlias属性为了安全性会把指定的物理路径做一个别名/cgi-bin/,以便隐藏在系统中真实的位置。这个物理路径下的所有可执行文件均会当成CGI程序来执行,无论后缀是什么可执行就行。
#
# "/var/www/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
2)配置/cgi-bin/目录以外的其他目录,让该目录下的可执行文件也被当成CGI程序来执行,否则Apache就只会显示文件内容。
<Directory "/var/www/html/abc">
Options Indexes FollowSymLinks ExecCGI
AllowOverride None
Order allow,deny
Allow from all
</Directory>
#设置该目录下哪些后缀的可执行文件会被当初CGI程序来执行,我们设置后缀为.cgi和.pl的文件被当初CGI程序来执行,其他可执行文件不会。
AddHandler cgi-script .cgi .pl