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
如果遇到 以下错误:
如果遇到 以下错误:

<code class="hljs erlang has-numbering">. /autogen. sh: x: autoreconf: <span class="hljs-keyword">not</span> found</code><ul style="" class="pre-numbering"><li>1</li></ul>

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

<code class="hljs bash has-numbering"><span class="hljs-built_in">sudo</span> apt-get install autoconf automake libtool </code><ul style="" class="pre-numbering"><li>1</li></ul>

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
解决办法:

<code class="hljs bash has-numbering"><span class="hljs-built_in">cd</span> include
<span class="hljs-built_in">sudo</span> vi fcgio.h</code><ul style="" class="pre-numbering"><li>1</li><li>2</li></ul>

头文件添加

<code class="hljs vala has-numbering"><span class="hljs-preprocessor">#include <stdio.h></span></code><ul style="" class="pre-numbering"><li>1</li></ul>

再次运行
make
sudo make install

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

fcgi_demo.c

<code class="hljs perl has-numbering"><span class="hljs-comment">#include <stdio. h></span>
<span class="hljs-comment">#include <stdlib. h></span>
<span class="hljs-comment">#include <string. h></span>
<span class="hljs-comment">#include <unistd. h></span>
<span class="hljs-comment">#include "fcgi_stdio. h"</span>

<span class="hljs-keyword">int</span> main( <span class="hljs-keyword">int</span> argc, char <span class="hljs-variable">*argv</span>[] )
{
<span class="hljs-keyword">int</span> count = <span class="hljs-number">0</span>;
<span class="hljs-keyword">while</span> ( FCGI_Accept( ) >= <span class="hljs-number">0</span>) {
<span class="hljs-keyword">printf</span>( <span class="hljs-string">"Content- type: text/html\r\n"</span>) ;
<span class="hljs-keyword">printf</span>( <span class="hljs-string">"\r\n"</span>) ;
<span class="hljs-keyword">printf</span>( <span class="hljs-string">"<title>Fast CGI Hello! </title>"</span>) ;
<span class="hljs-keyword">printf</span>( <span class="hljs-string">"<h1>Fast CGI Hello! </h1>"</span>) ;
<span class="hljs-keyword">printf</span>( <span class="hljs-string">"Request number <span class="hljs-variable">%d</span> running on host <i><span class="hljs-variable">%s</span></i>\n"</span>, ++count, getenv( <span class="hljs-string">"SERVE
R_NAME"</span>) ) ;
}
<span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;
}</code><ul style="" class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li><li>12</li><li>13</li><li>14</li><li>15</li><li>16</li><li>17</li><li>18</li><li>19</li></ul>

*编译:

<code class="hljs lasso has-numbering">gcc fcgi_demo<span class="hljs-built_in">.</span>c <span class="hljs-attribute">-o</span> demo <span class="hljs-attribute">-lfcgi</span></code><ul style="" class="pre-numbering"><li>1</li></ul>

配置fastcgi.conf

<code class="hljs bash has-numbering"><span class="hljs-built_in">cd</span> usr/local/nginx/conf
<span class="hljs-built_in">sudo</span> vi nginx.conf</code><ul style="" class="pre-numbering"><li>1</li><li>2</li></ul>

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

<code class="hljs avrasm has-numbering">location /demo {
                      fastcgi_pass <span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>:<span class="hljs-number">9001</span><span class="hljs-comment">;</span>
                     fastcgi_index demo<span class="hljs-preprocessor">.cgi</span><span class="hljs-comment">;</span>
                     include fastcgi<span class="hljs-preprocessor">.conf</span><span class="hljs-comment">;</span>
                         }
         location = /upload<span class="hljs-preprocessor">.cgi</span>{
                      root html<span class="hljs-comment">;</span>
                      index upload<span class="hljs-preprocessor">.html</span><span class="hljs-comment">;</span>
                                }

          location = /upload/UploadAction{
                      fastcgi_pass <span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>:<span class="hljs-number">9002</span><span class="hljs-comment">;</span>
                      fastcgi_index echo<span class="hljs-preprocessor">.cgi</span><span class="hljs-comment">;</span>
                      include fastcgi<span class="hljs-preprocessor">.conf</span><span class="hljs-comment">;</span>
                                       }</code><ul style="" class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li><li>12</li><li>13</li><li>14</li><li>15</li></ul>

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

<code class="hljs avrasm has-numbering">tar -zxvf zyfile<span class="hljs-preprocessor">.tar</span><span class="hljs-preprocessor">.gz</span>
cd zyfile<span class="hljs-preprocessor">.tar</span><span class="hljs-preprocessor">.gz</span>
./configure
make
sudo make install</code><ul style="" class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li></ul>

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

<code class="hljs avrasm has-numbering">sudo mv demo<span class="hljs-preprocessor">.html</span> upload<span class="hljs-preprocessor">.html</span></code><ul style="" class="pre-numbering"><li>1</li></ul>

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

<code class="hljs ruby has-numbering">sudo mv * <span class="hljs-regexp">/usr/local</span><span class="hljs-regexp">/nginx/html</span></code><ul style="" class="pre-numbering"><li>1</li></ul>

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

依次运行

<code class="hljs lasso has-numbering">spawn<span class="hljs-attribute">-fcgi</span> <span class="hljs-attribute">-a</span> <span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span> <span class="hljs-attribute">-p</span> <span class="hljs-number">9001</span> <span class="hljs-attribute">-f</span> <span class="hljs-built_in">.</span>/test/echo

spawn<span class="hljs-attribute">-fcgi</span> <span class="hljs-attribute">-a</span> <span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span> <span class="hljs-attribute">-p</span> <span class="hljs-number">9002</span> <span class="hljs-attribute">-f</span> <span class="hljs-built_in">.</span>/test/echo</code><ul style="" class="pre-numbering"><li>1</li><li>2</li><li>3</li></ul>

出现两次PID= xxxxx则成功

重启nginx

<code class="hljs bash has-numbering"><span class="hljs-built_in">sudo</span> /usr/local/nginx/sbin/ <span class="hljs-operator">-s</span> reload</code><ul style="" class="pre-numbering"><li>1</li></ul>

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

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

进入git

<code class="hljs go has-numbering"><span class="hljs-built_in">make</span> clean

<span class="hljs-built_in">make</span></code><ul style="" class="pre-numbering"><li>1</li><li>2</li><li>3</li></ul>

依次运行

<code class="hljs lasso has-numbering">spawn<span class="hljs-attribute">-fcgi</span> <span class="hljs-attribute">-a</span> <span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span> <span class="hljs-attribute">-p</span> <span class="hljs-number">9001</span> <span class="hljs-attribute">-f</span> <span class="hljs-built_in">.</span>/test/echo

spawn<span class="hljs-attribute">-fcgi</span> <span class="hljs-attribute">-a</span> <span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span> <span class="hljs-attribute">-p</span> <span class="hljs-number">9002</span> <span class="hljs-attribute">-f</span> <span class="hljs-built_in">.</span>/test/echo</code><ul style="" class="pre-numbering"><li>1</li><li>2</li><li>3</li></ul>

出现两次PID= xxxxx则成功

重启nginx

<code class="hljs bash has-numbering"><span class="hljs-built_in">sudo</span> /usr/local/nginx/sbin/ <span class="hljs-operator">-s</span> reload</code><ul style="" class="pre-numbering"><li>1</li></ul>

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值