Spawn-FCGI安装

Spawn-FCGI安装

获取spawn-fcgi编译安装包, 在 http://redmine.lighttpd.net/projects/spawn-fcgi/wiki 上可
以获取当 前最新的版本。

tar -zxvf spawn-fcgi-x.x.x.tar.gz
cd spawn-fcgi-x.x.x.tar.gz
./configure。
make
sudo make install
如果遇到 以下错误:
如果遇到 以下错误:

. /autogen. sh: x: autoreconf: not found

因为没有安装automake 工具, ubuntu用 下面的命令安装好就可以了

sudo apt-get install autoconf automake libtool 

spawn-fcgi的帮 助信息可以通过man spawn-fcgi或spawn-fcgi –h获得, 下面是部分常用
spawn-fcgi参数信息:

Nginx与FastCGI

f 指定调用 FastCGI的进程的执行程序位置
- a 绑定到 地址addr。
- p 绑定到 端口 port。
- s 绑定到 unix domain socket
- C 指定产 生的FastCGI的进程数, 默认为 5。 ( 仅用 于PHP)
- P 指定产 生的进程的PID文件路径。
- F 指定产 生的FastCGI的进程数( C的CGI用 这个)
- u和- g FastCGI使用 什么 身 份( - u 用 户 - g 用 户 组) 运行,
CentOS下可以使用 apache用 户 , 其他的根据情况配置, 如nobody、 www- data等。

fastgci应 用 程序

使用 C/C++编写 fastcgi应 用 程序, 可以使用 FastCGI软件开发套件或者其它开发框架, 如
fastcgi++。
本文使用 FastCGI软件开发套件——fcgi
http://www.filewatcher.com/d/Gentoo/distfiles/Other/fcgi-2.4.1 -SNAP-
091 0052249.tar.gz.61 4929.html
通过此套件可以轻松编写 fastcgi应 用 程序, 安装fcgi:
. /configue
make
如果编译出 现类似以下错误:
6.3 Nginx与FastCGI
94
cgio. 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
解决办法:

cd include
sudo vi fcgio.h

头文件添加

#include <stdio.h>

再次运行
make
sudo make install

编写一个fcgi简单的应用程序:

fcgi_demo.c

#include <stdio. h>
#include <stdlib. h>
#include <string. h>
#include <unistd. h>
#include "fcgi_stdio. h"

int main( int argc, char *argv[] )
{
int count = 0;
while ( FCGI_Accept( ) >= 0) {
printf( "Content- type: text/html\r\n") ;
printf( "\r\n") ;
printf( "<title>Fast CGI Hello! </title>") ;
printf( "<h1>Fast CGI Hello! </h1>") ;
printf( "Request number %d running on host <i>%s</i>\n", ++count, getenv( "SERVE
R_NAME") ) ;
}
return 0;
}

*编译:

gcc fcgi_demo.c -o demo -lfcgi

打开浏览器

192.168.21.128

nginx欢迎界面

配置fastcgi.conf

cd usr/local/nginx/conf
sudo vi nginx.conf

把下面代码复制到
nginx.conf文件里

location /demo {
                      fastcgi_pass 127.0.0.1:9001;
                     fastcgi_index demo.cgi;
                     include fastcgi.conf;
                         }
         location = /upload.cgi{
                      root html;
                      index upload.html;
                                }

          location = /upload/UploadAction{
                      fastcgi_pass 127.0.0.1:9002;
                      fastcgi_index echo.cgi;
                      include fastcgi.conf;
                                       }

将zyfile.tar.gz复制到
/usr/local/nginx/html
解压

tar -zxvf zyfile.tar.gz
cd zyfile.tar.gz
./configure
make
sudo make install

然后将demo.html改名为upload.html

sudo mv demo.html upload.html

并把所有文件包括文件夹移动到
/usr/local/nginx/html目录下

sudo mv * /usr/local/nginx/html

会根据配置好的文件,去/usr/local/nginx/html目录下寻找zy工具。如果目录下没有移动过来的文件,则会出现404错误。

依次运行

spawn-fcgi -a 127.0.0.1 -p 9001 -f ./test/echo

spawn-fcgi -a 127.0.0.1 -p 9002 -f ./test/echo

出现两次PID= xxxxx则成功

重启nginx

sudo /usr/local/nginx/sbin/ -s reload

打开浏览器,输入ip地址192.168.21.128/upload.html
出现上传界面
选择文件,上传成功!

系统重启,需进行以下步骤操作:

进入git

make clean

make

依次运行

spawn-fcgi -a 127.0.0.1 -p 9001 -f ./test/echo

spawn-fcgi -a 127.0.0.1 -p 9002 -f ./test/echo

出现两次PID= xxxxx则成功

重启nginx

sudo /usr/local/nginx/sbin/ -s reload

打开浏览器,输入ip地址192.168.21.128/upload.html
出现上传界面
选择文件,上传成功!
上传成功

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值