一、源码安装apache
之前为了测试系统,自己下载源码编译安装了一个apache2.4,安装apache2.4过程比较简单,注意在configure时加上参数。
配置:
./configure --prefix=$APACHE_HOME --enable-mods-shared=most --enable-ssl=shared --with-ssl=$SSL_HOME(--with-ssl是开启SSL工具,可选项),详细参数可参见:
apache配置参数
编译安装:
make
make install
然后就可以使用bin/apachectl -k start和bin/apachectl -k stop开启和关闭apache了。
如果有错误请参见http://xtony.blog.51cto.com/3964396/836508
二、apache配置支持cgi
需要注意的一点是apache2.4要支持cgi需要将conf/httpd.conf中的这一行注释取消。
LoadModule cgid_module modules/mod_cgid.so
同时,在cgi-bin目录的设置如下:
<Directory "/XXX/apache2/cgi-bin">
AllowOverride None
Options +ExecCGI
AddHandler cgi-script .cgi
Require all granted
</Directory>
这样配置好后就可以调用cgi程序了。下面是一个python cgi程序,在浏览器打开HTTP://localhost/cgi-bin/test.cgi即可打印输出语句。
#!/usr/bin/python
print "Content-type:text/html\r\n\r\n"
print ''
print ''
print 'Hello Word - First CGI Program'
print ''
print ''
三、安装fastcgi模块
1.下载fastcgi模块源码,
https://github.com/ByteInternet/libapache-mod-fastcgi。最新的应该是2.4.6版本。
2.解压fastcgi模块源码,得到目录mod_fastcgi-2.4.6,并进入该目录。
3.下载fastcgi模块针对apache2.4的补丁文件:
http://leeon.me/upload/other/byte-compile-against-apache24.diff
4.对fastcgi模块源码打补丁,命令为:
patch -p1 < byte-compile-against-apache24.diff
5.将目录下面的文件Makefile.AP2改名为Makefile,便于后面的编译。同时,修改该文件里面的top_dir为你的apache安装的路径。
6.编译安装。
make&&make install7.在$APACHE_HOME/conf/httpd.conf中加入载入模块的语句:
LoadModule fastcgi_module modules/mod_fastcgi.so
四、apache配置虚拟主机
apache可配置虚拟主机,使得可以使用同一个ip地址的多个端口建立不同的站点。配置虚拟主机的文件为$APACHE_HOME/conf/extra/httpd-vhost.conf。我的配置如下,其中监听端口为8888,采用了fastcgi负责执行cgi程序。
Listen 8888
<VirtualHost *:8888>
ServerAdmin shishujuanhust@163.com
DocumentRoot "$PATH"
<IfModule alias_module>
ScriptAlias /cgi-bin/ $PATH/cgi-bin/
</IfModule>
<Directory />
AllowOverride none
Require all granted
</Directory>
<Directory "$PATH/cgi-bin">
Options Indexes FollowSymLinks
Options +ExecCGI
AllowOverride None
Order allow,deny
Allow from 192.168
</Directory>
AddHandler fastcgi-script .cgi
ErrorLog "$PATH/logs/apache_error_log"
CustomLog "$PATH/logs/apache_access_log" common
</VirtualHost>
五、运行fcgi程序
在第四节配置好虚拟主机后,就可以来运行fcgi程序了。在运行fcgi程序之前,可先安装一个fcgi包,地址
http://jonpy.sourceforge.net/fcgi.html。
安装好后,根据文档中的说明,写出第一个fcgi程序如下:
#!/usr/bin/python ##这一行一定要加,不然会出错。
import jon.cgi as cgi
import jon.fcgi as fcgi
class Handler(cgi.Handler):
def process(self, req):
req.set_header("Content-Type", "text/plain")
req.write("Hello, world!\n")
fcgi.Server({fcgi.FCGI_RESPONDER: Handler}).run()
Apache2.4配置CGI与FastCGI指南

本文档详细介绍了如何在Apache2.4上进行源码安装,并配置支持CGI和FastCGI。从源码编译安装Apache,到配置CGI支持,安装FastCGI模块,再到配置虚拟主机,最后运行FastCGI程序,每个步骤都有清晰的说明。
1609

被折叠的 条评论
为什么被折叠?



