fastCGI的安装和使用
来源:互联网 发布:网络平台赌博游戏 编辑:程序博客网 时间:2024/05/11 20:44
一、安装
1 先安装2个包
spawn-fcgi-1.6.4.tar.gzfcgi-2.4.1-SNAP-0910052249
安装 fcgi-2.4.1-SNAP-0910052249
报错:
fcgio.cpp: In destructor 'virtual fcgi_streambuf::~fcgi_streambuf()':
fcgio.cpp:50: error: 'EOF' was not declared in this scope
fcgio.cpp: In member function 'virtual int fcgi_streambuf::overflow(int)':
fcgio.cpp:70: error: 'EOF' was not declared in this scope
fcgio.cpp:75: error: 'EOF' was not declared in this scope
fcgio.cpp: In member function 'virtual int fcgi_streambuf::sync()':
fcgio.cpp:86: error: 'EOF' was not declared in this scope
fcgio.cpp:87: error: 'EOF' was not declared in this scope
fcgio.cpp: In member function 'virtual int fcgi_streambuf::underflow()':
fcgio.cpp:113: error: 'EOF' was not declared in this scope
make[2]: *** [fcgio.lo] Error 1
make[2]: Leaving directory `/root/downloads/fcgi-2.4.1-SNAP-0910052249/libfcgi'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/root/downloads/fcgi-2.4.1-SNAP-0910052249'
make: *** [all] Error 2
解决办法:在/include/fcgio.h文件中加上 #include <cstdio>,然后再编译安装就通过了。
2 编写测试代码
1) mkdir test
vi demo.c
输入下列代码:
#include "fcgi_stdio.h"
#include <stdlib.h>
int main(void)
{
int count = 0;
while (FCGI_Accept() >= 0)
printf("Content-type: text/html\r\n"
"\r\n"
"<title>FastCGI Hello!</title>"
"<h1>FastCGI Hello!</h1>"
"Request number %d running on host <i>%s</i>\n",
++count, getenv("SERVER_NAME"));
return 0;
}
2) 编译
g++ demo.c -o demo.cgi -lfcgi
3) ldd demo.cgi
[wdm@localhost test]$ ldd demo.cgi
linux-vdso.so.1 => (0x00007fffc390b000)
libfcgi.so.0 => not found
libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00000035eae00000)
libm.so.6 => /lib64/libm.so.6 (0x00000035e5e00000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00000035ea200000)
libc.so.6 => /lib64/libc.so.6 (0x00000035e5600000)
/lib64/ld-linux-x86-64.so.2 (0x00000035e4e00000)
解决:
查找动态库位置
sudo find / -name 'libfcgi.so'
/usr/local/lib/libfcgi.so
/home/wdm/opensource/fcgi-2.4.1-SNAP-0910052249/libfcgi/.libs/libfcgi.so
配置动态库搜索路径
sudo vi /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/lib/
/usr/lib64/
/usr/lib/
生效
sudo ldconfig -v
3 启动fcgi程序
[wdm@localhost test]$ spawn-fcgi -a 127.0.0.1 -p 8081 -f ./demo.cgi
spawn-fcgi: child spawned successfully: PID: 11819
4 nginx fastcgi配置
打开配置文件
sudo vi nginx.conf
配置内容
location = /50x.html {
root html;
}
location = /demo.cgi {
fastcgi_pass 127.0.0.1:8081;
fastcgi_index index.cgi;
include fastcgi.conf;
}
重启
sudo ./nginx -s reload
5) 测试
http://192.168.255.137/demo.cgi
FastCGI Hello!
Request number 1 running on host localhost
二、使用
1、fastCGI环境变量
CGI程序通过标准输入(STDIN)和标准输出(STDOUT)来进行输入输出。此外CGI程序还通过环境变量来得到输入,操作系统提供了许 多环境变量,它们定义了程序的执行环境,应用程序可以存取它们。Web服务器和CGI接口又另外设置了一些环境变量,用来向CGI程序传递一些重要的参 数。CGI的GET方法还通过环境变量QUERY-STRING向CGI程序传递Form中的数据。 下面是一些常用的CGI环境变量:
2、fastCGI例子
FCGX_Stream *in, *out, *err;
FCGX_ParamArray evnp;
while(FCGX_Accept(&in, &out, &err, &evnp) >= 0)
{
char *query = FCGX_GetParam("QUERY_STRING", evnp); //获取请求
try
{
}
catch(exception &e)
{
TRACE(LOG_ERROR, "error: " << e.what());
return -1;
}
}
FCGX_FPrintF(out, "Content-type: text/json;charset=utf-8\r\n"
"Content-Length: %d\r\n"
"\r\n"
"%s", ... , ....);
- fastCGI的安装和使用
- 什么是FastCGI和FastCGI的优点
- php安装模式mod_php和Fastcgi的选择与对比
- php安装模式mod_php和Fastcgi的选择与对比
- php安装模式mod_php和Fastcgi的选择与对比
- Nginx与PHP(FastCGI)的安装、配置和优化
- Fastcgi+apache的安装方式
- IIS6+fastcgi+php的安装
- FastCGI的编译和移植
- CGI和FastCGI的区别
- CGI和FastCGI的区别
- FastCGI和CGI的区别
- cgi和fastcgi的区别
- 安装PHP5.5+和FASTCGI方式运行
- apache使用fastcgi配置python和php
- fastcgi Linux环境下的安装
- 安装nginx,flup,django的fastcgi模式
- 在Ubuntu 8.04 LTS(hardy)下安装配置nginx和fastcgi方式的php
- 老王(三)谈埋点:人生处处有埋点
- Java环境变量
- ImageLoader工具类
- 自动打码软件常见问题解答
- csv文件
- fastCGI的安装和使用
- eclipse构建及运行maven web项目
- css3中的滤镜效果
- java--DBUtils数据库操作工具包
- jQuery插件之ajaxFileUpload.未测试
- Allegro设置及实用小技巧(二)
- axis2系列之会话(session)管理
- 视觉跟踪综述
- MEMCACHED默认最大过期时间