在lighttpd上开发fastcgi程序需要安装两个库
一、安装开发库
1) fcgi
http://fastcgi.com/dist/fcgi-2.4.0.tar.gz
fcgi用于处理fastCGI请求
2) rudeCGI
http://rudeserver.com/cgiparser/download/rudecgi-5.0.0.tar.bz2
rudeCGI用于解析http request参数的KVP对
例如:一个WMS的GetCapabilities请求(http://www.opengeospatial.org/standards/wms)
http://10.0.0.136:2087/world/wms?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities
http request参数为:SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities
通过rudeCGI可以这样方位KVP对
rude::CGI cgi;
cgi["SERVICE"];
cgi["VERSION"];
cgi["REQUEST"];
值分别是:
WMS
1.3.0
GetCapabilities
并且rudecgi可以从接受从stdin传输的字符串,从而可以在命令行下调试fastcgi程序
rudecgi-5.0.0.tar.bz2源码本身有点问题,需要做一点修改。
修改AbstractImplementation.cpp文件的instance()函数为
AbstractImplementation* AbstractImplementation::instance()
{
if(!s_instance)
{
finished=false;
s_instance = new Implementation();
}
return s_instance;
}
1、安装fcgi
#tar zxvf fcgi-2.4.0.tar.gz
#cd fcgi-2.4.0
#./configure
#make
#make install
2、安装rudecgi-5.0.0.tar.bz2
修该rudecgi的源码后,安装rudecgi
#tar jxvf rudecgi-5.0.0.tar.bz2
#./configure
#make
#make install
二、编写fastcgi程序
安装完rudecgi和fcgi以后就可以用C/C++写fastcgi程序了,下面是个fastcgi的小程序
#vi fcgitest.cpp
#include <rude/cgi.h>
#include <fcgi_stdio.h>
#include <fcgi_config.h>
#include "stdlib.h"
#include "stdio.h"
int main(int argc, char* argv[])
{
int count = 0;
while(FCGI_Accept_t() >= 0)
{
rude::CGI cgi();
//输出http头
//mime type是text/plain类型
//http head和body之间要有一个空行,所以输出两个\r\n
printf("ContentType: text/plain \r\n" "\r\n");
//输入计数器
printf("count:%d ", count++);
printf("<br>");
//输出http requst的kvp的值
printf("Service:%s", cgi["SERVICE"]);
printf("<br>");
printf("Version:%s", cgi["VERSION"]);
printf("<br>");
printf("Request:%s", cgi["REQUEST"]);
printf("<br>");
//http response结束
printf("\n\n");
cgi.finish();
}
return 0;
}
编译fcgitest.cpp
#g++ -o fcgitest.cgi fcgitest.cpp -lfcgi++ -lrudecgi
生成fcgitest.cgi程序
在命令行下就可以运行fcgitest.cgi程序
#./fcgitest.cgi
就可以运行
三、将fcgitest.cgi程序配置到lighttpd中
在lighttpd中配置fastcgi需要打开fastcgi的mod
打开lighttpd的配置文件lighttpd.conf
去掉server.modules下面的"mod_fastcgi"模块的注释符“#”。
在lighttpd.conf中找到
#fastcgi.server = (
一行,我这里是在225行,这里就是lighttpd配置fastcgi的部分。默认有一个php的配置。
现在就把刚才写的fcgitest.cgi程序配置到lighttpd中去。
配置文件如下:
"/fastcgi" =>
( "localhost" =>
(
#unix socket的路径
"socket" => "/tmp/fcgitest-fcgi.socket",
"check-local" => "disable",
#fastcgi应用程序的路径
"bin-path" => "/opt/fcgitest/fcgitest.fcgi",
"idle-timeout" => 10,
#当访问量增大的时候lighttpd启动的最小和最大进程数的设置
#这里设置最少启动一个进程,最多启动10个进程
"min-procs" => 1,
"max-procs" => 10
)
)
配置完以后的fastcgi.server节点为:
#fastcgi.server= (
# ".php" =>
# ( "localhost" =>
# (
# "socket" => "/var/run/lighttpd/php-fastcgi.socket",
# "bin-path" => "/usr/local/bin/php-cgi"
# )
# )
# ,
"/fastcgi" =>
( "localhost" =>
(
"socket" => "/tmp/fcgitest-fcgi.socket",
"check-local" => "disable",
"bin-path" => "/opt/fcgitest/fcgitest.fcgi",
"idle-timeout" => 10,
"min-procs" => 1,
"max-procs" => 10
)
)
)
配置完以后重新启动lighttpd
#/etc/init.d/lighttpd restart
然后就可以在浏览器里面访问fcgitest服务了
URL:
http://10.0.0.136:2087/fcgitest?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities
分享到:
相关推荐
centos系统下的/bin/sh
配套说明: http://blog.csdn.net/gogoytgo/article/details/79420745
OS: CentOS release 5.5 Lighttpd: 1.4.28 安装 sudo yum install lighttpd.i386 lighttpd-fastcgi.i386 lighttpd-mod_mysql_vhost.i386 运行 检查配置文件 lighttpd -t -f lighttpd.conf 启动lighttpd服务 ...
CentOS上配置LVS DR集群.docx CentOS上配置LVS DR集群.docx
CentOS Apache配置详解CentOS Apache配置详解
由于安装centos后的默认yum源为centos的官方地址,所以在国内使用很慢甚至无法访问,所以一般的做法都是把默认的yum源替换成aliyun的yum源或者163等国内的yum源(下文介绍如何配置)。 但是以上的方法都是需要网络的...
http://mirrors.btte.net/centos/7/isos/x86_64/ http://mirrors.cn99.com/centos/7/isos/x86_64/ http://mirrors.sohu.com/centos/7/isos/x86_64/ http://mirrors.aliyun.com/centos/7/isos/x86_64/ ...
centos7.3配置zabbix3.2/3.4包括server、agent、proxy的配置
CentOS7各个版本镜像下载地址 # CentOS7.6 下载地址 ...http://mirrors.163.com/centos/7.6.1810/isos/x86_64/CentOS-7-x86_64-DVD-1810.iso # CentOS-7-x86_64-Everything-1810.iso CentOS 7.6 Everything版 10G ...
【linux】CentOS 5/6/7 对应版本 repo文件: 可用于解决以下问题: (1)CentOS 报错:There are no enabled repos; (2)yum repolist为0,yum list正常; (3)yum安装无法使用。
Centos7/8下.vimrc脚本固定格式配置
现在我们常见的一些关于Linux的系统很多,但是使用的更多的一般都是CentOS和Ubuntu,今天我就来记录一下关于centos下java的安装和环境变量的配置。 首先使用xshell连接到centos7,我使用的是centos7 *64位,所以一切...
centOS完全配置手册 centOS完全配置手册 centOS完全配置手册 centOS完全配置手册 centOS完全配置手册
./yum_source_change.sh 2 xxxx/centos.iso 两个运行参数 2表示执行yum源安装 xxx/centos.iso表示镜像文件全路径 参数说明:1.ftp源安装,2.yum源安装,3.设置aliyun Centos-5.repo,4.设置aliyun Centos-6.repo,5....
Centos6.5+Qt5.1.0开发环境配置,包括系统源的更改,gcc安装和glibc-2.14的安装和编译后应用程序的打包等注意事项
一、实验目的:熟悉爬虫和Python常用爬虫库,在CentOS7上掌握用于存储爬取的数据的MySQL、MongoDB数据库的配置方法。 二、实验内容:爬虫的原理、Python常用爬虫库、配置MySQL数据库、配置MongoDB数据库 三、实验...
CentOS7配置本地yum源(超详细过程)
在linux(我测的为centos)下的TCP/IP测试小程序,linux当服务器端,在终端运行这个程序编译出来的“.o”文件,程序下客户端发送“test tcp/ip ,good”字符串.
CentOS的iso文件最新版下载方法,和历史版下载方法; CentOS的安装方法和常用配置方法;
Centos7.9安装配置vsftpd