Hello World FastCGI

什么是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/* ");
        FCGI_printf("FastCGI Hello! Request number %d ",++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!


原文地址:https://www.cnblogs.com/yjbjingcha/p/6941379.html