fastcgi(一)

时间:2023-03-09 19:01:24
fastcgi(一)

首先安装 fastcgi 开发包 ...

#wget http://www.fastcgi.com/dist/fcgi-current.tar.gz

#tar -zxvf fcgi-current.tar.gz

#cd fcgi-2.4.0

#./configure --prefix=/usr/local/fastcgi/

#make && make install

写一个简单的fcgi 程序

#vim hello.c

内容如下:

  1. #include </usr/local/fastcgi/include/fcgi_stdio.h>
  2. int main(void){
  3. while( FCGI_Accept() >= 0){
  4. printf( "Content-Type: text/html\r\n" );
  5. printf("\r\n");
  6. printf( "Hello world in C\n" );
  7. }
  8. }

#gcc -o hello.fcgi hello.c -L /usr/local/fastcgi/lib/ -lfcgi

[root@lxp2 Downloads]# tar -xf nginx-1.0.10.tar.gz 

[root@lxp2 Downloads]# cd nginx-1.0.10

[root@lxp2 nginx-1.0.10]# ./configure

checking for PCRE library ... not found

checking for PCRE library in /usr/local/ ... not found

checking for PCRE library in /usr/include/pcre/ ... not found

checking for PCRE library in /usr/pkg/ ... not found

checking for PCRE library in /opt/local/ ... not found





./configure: error: the HTTP rewrite module requires the PCRE library.

You can either disable the module by using --without-http_rewrite_module

option, or install the PCRE library into the system, or build the PCRE library

statically from the source with nginx by using --with-pcre=<path> option.

这说明系统中缺少PCRE库。该库是实现正则表达式的基础,如果缺少此库,nginx无法支持HTTP中的URL重写功能。如果你不需要此功能,可以在执行编译配置脚本时加入“--without-http_rewrite_module”。但是,这里我们需要这项功能。于是下载PCRE库。

2.下载安装PCRE库:

PCRE库是实现Perl式正则表达式的基础。如果系统中缺少此库需要编译安装。可以从著名的开源软件网站sourceforge上下载:http://sourceforge.net/projects/pcre/files/pcre/。目前最新版本是8.20。

仍然是下载后解压、配置、编译和安装:

nginx path prefix: "/usr/local/nginx"

  nginx binary file: "/usr/local/nginx/sbin/nginx"

  nginx configuration prefix: "/usr/local/nginx/conf"

  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"

  nginx pid file: "/usr/local/nginx/logs/nginx.pid"

  nginx error log file: "/usr/local/nginx/logs/error.log"

  nginx http access log file: "/usr/local/nginx/logs/access.log"

  nginx http client request body temporary files: "client_body_temp"

  nginx http proxy temporary files: "proxy_temp"

  nginx http fastcgi temporary files: "fastcgi_temp"

  nginx http uwsgi temporary files: "uwsgi_temp"

  nginx http scgi temporary files: "scgi_temp"

[root@lxp2 nginx-1.0.10]# make

[root@lxp2 nginx-1.0.10]# sudo make install

nginx.conf的配置要修改

  1. server {
  2. listen 80;
  3. location ~ \.fcgi$ {
  4. root           /srv/www;
  5. fastcgi_pass   127.0.0.1:9002;
  6. include        fastcgi_params;
  7. }
  8. }

重启nginx ,然后用fastcgi 启动程序,同时监听 9002 端口

# /usr/local/fastcgi/bin/cgi-fcgi -start -connect 127.0.0.1:9002 /srv/html/cgi/hello.fcgi