第五弹——apache配置fastcgi&C/C++

来源:互联网 发布:java八种基本类型 编辑:程序博客网 时间:2024/06/05 07:35

上一篇简单介绍了fastcgi,那么这篇就讲讲fastcgi该怎么用。


在apache上配置fastcgi模块:

首先我们需要安装一个fastcgi模块,它的官方版早就停止更新了,所以我们这里用的是apache自带的fcgid,下载

#wget http://www.apache.org/dist/httpd/mod_fcgid/mod_fcgid-2.3.9.tar.gz

这是最新版本了。
下载完成之后解压

#tar -zxvf mod_fcgid-2.3.9.tar.gz

然后进入文件夹

#cd mod_fcgid-2.3.9

这里需要记住一点,文件夹里的configure后缀名为apxs,打开它可以看出来里面的路径都没有设置,所以需要

#APXS=/usr/local/apache/bin/apxs ./configure.apxs

这里的usr/local/httpd/bin/是你的安装地址,搞定之后就可以

./configuremakemake install

完成,然后开始配置,其实配置也很简单

<Directory "/usr/local/httpd/cgi-bin">      AllowOverride None      Options Indexes ExecCGI       Order allow,deny      Allow from all  </Directory>  AddHandler cgi-script .cgi .py  

好了之后重启httpd

service httpd restart

C的cgi实现:

#include "fcgi_stdio.h"  #include <stdlib.h>  void main(void)  {      int count = 0;      while(FCGI_Accept() >= 0)      printf("Content-type: text/html\r\n"             "\r\n"             "<title>FastCGI Hello!</title>"             "<h1>FastCGI Hello!</h1>"             "Request number %d running on host <i>%s</i>\n",              ++count, getenv("SERVER_NAME"));     return 0; }  

然后编译

gcc -o fcgi_test.fcgi cgi_test.c -I/usr/local/include -L/usr/local/lib -lfcgi

有些人可能会提示找不到fcgi_stdio.h笔者试了好多方法都没法解决,最后安装了原版的fastcgi,使用了它自带的fcgi_stdio.h终于解决了问题。(可以下载我的资源,直接在win下解压,传到linux上就可以直接安装了)戳此下载

原创粉丝点击