标签:style class tar ext color int
什么是FastCGI,google吧,测试一个用C++实现的FastCGI程序。
1, Nginx 安装,http://nginx.org/en/download.html.下载解压,configure,make ,make install.安装过程中确实包,需要先下载安装依赖包
2,安装lighttpd的spawn-fastcgi
下载http://www.lighttpd.net/download/lighttpd-1.4.19.tar.gz
./configure
make
make install
cp ./src/spawn-fcgi /usr/local/nginx/sbin
3,安装fastcgi库
下载http://www.fastcgi.com/dist/fcgi.tar.gz
./configure
make
make install
安装过程中缺少库,需要现在安装依赖库
4,Helloworld.cpp
#include <iostream>
#include <fcgi_stdio.h>
using namespace std;
int main()
{
int count = 0;
while (FCGI_Accept() >= 0)
{
FCGI_printf("Content-type: text/*\r\n\r\n");
FCGI_printf("FastCGI Hello! Request number %d \n",++count);
}
}
5,编译程序,启动Spawn-cgi
g++ -lfcgi++ -o helloworld Helloworld.cpp
启动
/usr/local/nginx/sbin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 25 -f /usr/local/nginx/fastcgi_temp/helloworld
6,修改nginx conf,启动(重新加载配置)服务
nginx.conf添加如下配置,重启nginx或者./nginx -s reload重新加载配置
location /cgi
{
fastcgi_pass 127.0.0.1:9000;
include /usr/local/nginx/conf/fastcgi.conf;
}
7,测试
打开浏览器,输入http://ip/cgi,就显示
FastCGI Hello! Request number 1
再输入显示FastCGI Hello! Request number 2
Bye Hello World!
Hello World FastCGI,布布扣,bubuko.com
标签:style class tar ext color int
原文地址:http://blog.csdn.net/liuzhoulong/article/details/25306855