什么是FastCGI
简单地说, FastCGI应用程序就像应用程序一样进行操作,不像 CGI应用程序,它始终处于
活动状态并为来自 Web服务器的请求提供服务。也就是说,每次处理时,它不必花费启动新进程和程序初始化的开销。
Apache如何支持 FastCGI
Apache可以通过两种方法来支持 FastCGI
1) Apache服务器中添加 mod_fastcgi.c模块来支持。
2) 使用cgi-fcgi的传统CGI应用程序运行 FastCGI应用程序。
2种方法只是形式上的实现,无法获得 FastCGI的优点,所以强烈建议使用第 1种方法实
现。
3. 重新编译 Apache以支持FastCGI
1) 获取Apache最新的 FastCGI模块:文件名是 mod_fastcgi.c,可以到 www.fastcgi.com中下
载。
2) 将模块文件拷贝到 Apache的源程序目录下 src/modules/standard子目录中。
3) 修 改 s r c目 录 下 的 编 译 配 置 文 件 C o n f i g u r a t i o n, 添 加 一 行 : A d d M o d u l e
modules/standard/mod_fastcgi.o
4) 运行“./configure”。
5) 运行make
6) 运行make install
这样就会在源程序目录下生成一个新的“ httpd”程序,用这个新的程序替掉原来的程序就
完成了整个过程。
4. 配置实例
完成上面的过程后,到 www.fastcgi.org下载FastCGI开发人员工具集 FastCGI Developer's Kit
放入/usr/local/fastcgi目录下(目录可选)。需要对 httpd.conf文件做相应的修改,为安全起见,建
议在修改之前备份原来的配置文件。下面是一个配置例子
ResourceConfig /dev/null
AccessConfig /dev/null
# 用于User命令的用户名称
User  FastCGI_User
# 用于Group命令的组名称
Group FastCGI_Group
StartServers 1
MinSpareServers 1
MaxSpareServers 1
ServerRoot /usr/local/etc/httpd
ErrorLog logs/error.log
TransferLog logs/access.log
AppClass /usr/local/fastcgi/examples/echo -initial -env SOMETHING=NOTHING
<Location /examples/echo>
SetHandler fastcgi-script
</Location>
AppClass /usr/local/fastcgi/examples/echo.fcg -port 8978
<Location /examples/echo.fcg
SetHandler fastcgi-script
</Location>
<Location /example/remote-echo>
SetHandler fastcgi-script
</Location>
注意 在此只列出了与 FastCGI有关配置,请根据这个修改 httpd.conf文件