FastCGI学习笔记Beginer

本文介绍如何在Ubuntu 12.04上安装并配置FastCGI及Spawn-Fcgi,通过示例程序验证功能,并最终整合Nginx实现服务发布。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1 安装fcgi

主页:http://www.fastcgi.com

下载:http://www.fastcgi.com/dist/fcgi.tar.gz, 我此时的版本是2.4.1,目标环境是ubuntu12.04

解压:tar -xzvf fcgi.tar.gz

安装:cd fcgixxxxx && configure && make && make install

果然还是遇到问题:

fcgio.cpp: In destructor 'virtual fcgi_streambuf::~fcgi_streambuf()':
fcgio.cpp:50:14: error: 'EOF' was not declared in this scope
fcgio.cpp: In member function 'virtual int fcgi_streambuf::overflow(int)':
fcgio.cpp:70:72: error: 'EOF' was not declared in this scope
fcgio.cpp:75:14: error: 'EOF' was not declared in this scope
fcgio.cpp: In member function 'virtual int fcgi_streambuf::sync()':
fcgio.cpp:86:18: error: 'EOF' was not declared in this scope
fcgio.cpp:87:41: error: 'EOF' was not declared in this scope
fcgio.cpp: In member function 'virtual int fcgi_streambuf::underflow()':
fcgio.cpp:113:35: error: 'EOF' was not declared in this scope


解决方法: 修改源码include/fcgio.h 包含头文件#include <cstdio>,在make && make install,问题解决。


2 安装spawn-fcgi

主页:http://redmine.lighttpd.net/

下载:http://download.lighttpd.net/spawn-fcgi/releases-1.6.x/spawn-fcgi-1.6.3.tar.gz

解压:tar -xzvf spawn-fcgi-1.6.3.tar.gz

安装:cd spawn-fcgixxxx && configure && make && make install

挺顺利,没遇到问题。


3 编写一个简单的Demo(抄来的)

#include <fcgi_stdio.h>
int main( int argc, char *argv[] )
{
    while( FCGI_Accept() >= 0 ) {
        printf( "Content-Type: text/plain\n\n" );
        printf( "Hello FastCGI\n" );
    }
    return 0;
}

编译得到hello_fcgi
4 启动fcgi

./spawn-fcgi -a 127.0.0.1 -p 9000 ./hello_fcgi &

这一步起初遇到问题,提示libfcgi.so.0没找到。

线检查ldconfig -p | grep fcgi看看是否有跟fcgi相关的so路径配置。如果没有则加载之运行ldconfig,再看看是否加上了。


5 配置nginx

修改nginx的配置

http {

........

server {

........

#添加一条:

location /fcgi {

fastcgi_pass 127.0.0.1:9000;

                }

}

}

启动nginx

${Nginx安装路径}/sbin/nginx

或者通知nginx reload 配置

${Nginx安装路径}/sbin/nginx -s reload

6 Enjoy It

打开浏览器,输入localhost/fcgi,Enjoy。



参考资料:

http://blog.csdn.net/difficulttofindaname/article/details/7628772

http://www.cnblogs.com/xiaouisme/archive/2012/08/01/2618398.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值