FastCGI学习笔记Beginer

来源:互联网 发布:搭建python开发环境 编辑:程序博客网 时间:2024/06/03 19:59

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。



参考资料:

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

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

原创粉丝点击