IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    [原]Hello World FastCGI

    liuzhoulong发表于 2014-05-08 15:08:13
    love 0

    什么是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
    #include

    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!




沪ICP备19023445号-2号
友情链接