第五弹——apache配置fastcgi&CC++

xiaoxiao2021-02-28  117

上一篇简单介绍了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/是你的安装地址,搞定之后就可以

./configure make make 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上就可以直接安装了)戳此下载

转载请注明原文地址: https://www.6miu.com/read-33832.html

最新回复(0)