http://linuxjcq.blog.51cto.com/3042600/718002
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://linuxjcq.blog.51cto.com/3042600/718002
1. 下载spawn-fcgi并安装
- http://download.lighttpd.net/spawn-fcgi/releases-1.6.x/spawn-fcgi-1.6.3.tar.gz -P /usr/local/src
- tar zxvf /usr/local/src/spawn-fcgi-1.6.3.tar.gz -P /usr/local/src
- cd /usr/local/src/spawn-fcgi-1.6.3
- ./configure
- make
- # 复制spawn-fcgi到/usr/local/bin/
- cp spawn-fcgi /usr/local/bin
2. 下载并安装fcgi库
- wget http://fastcgi.com/dist/fcgi-2.4.0.tar.gz -P /usr/local/src
- tar zxvf /usr/local/src/fcgi-2.4.0.tar.gz -C /usr/ocal/src
- cd /usr/local/src/fcgi-2.4.0
- ./configure
- make
- make install
编译过程有报错
- error: 'EOF' was not declared in this scope
解决办法:在include/fcgio.h文件中加上#include <cstdio>
- vi include/fcgio.h
- #include <iostream>
- # 添加下行
- #include <cstdio>
3. 安装fcgiwrap
- wget https://download.github.com/gnosek-fcgiwrap-1.0.3-4-g58ec209.tar.gz -P /usr/locl/src
- tar zxvf /usr/local/src/gnosek-fcgiwrap-1.0.3-4-g58ec209.tar.gz -P /usr/local/src
- cd /usr/local/src/gnosek-fcgiwrap-58ec209
- autoreconf -i
- export ac_cv_func_malloc_0_nonnull=yes
- ./configure
- make
- # 复制fcgiwrap
- cp fcgiwrap /usr/local/bin
4. 创建启动和管理脚本
- vi /etc/rc.d/init.d/cfcgi
- #!/bin/bash
- # cfcgi – this script starts and stops the fcgiwrap instance
- #
- # chkconfig: – 96 28
- # description: cfcgi
- # processname: cfcgi
- RETVAL=0
- case "$1" in
- start)
- echo "Starting fastcgi"
- /usr/local/bin/spawn-fcgi -f /usr/local/bin/fcgiwrap -a 192.168.1.10 -p 10000 -F 32 -P /tmp/fastcgi-c.pid -u nobody -g nobody
- RETVAL=$?
- ;;
- stop)
- echo "Stopping fastcgi"
- killall -9 fcgiwrap
- RETVAL=$?
- ;;
- restart)
- echo "Restarting fastcgi"
- killall -9 fcgiwrap
- /usr/local/bin/spawn-fcgi -f /usr/local/bin/fcgiwrap -a 192.168.1.10 -p 10000 -F 32 -P /tmp/fastcgi-c.pid -u nobody -g nobody
- RETVAL=$?
- ;;
- *)
- echo "Usage: c-fastcgi {start|stop|restart}"
- exit 1
- ;;
- esac
- exit $RETVAL
这个脚本是salogs.com中的,直接拿来用了
添加为服务
- chmod 0755 /etc/rc.d/init.d/cfcgi
- chown root:root /etc/rc.d/init.d/cfcgi
- chkconfig –add cfcgi
- chkconfig cfcgi on
5. 启动
- service cfcgi start
检验下:
- netstat -tlnp | grep "fcgiwrap"
- tcp 0 0 192.168.1.10:10000 0.0.0.0:* LISTEN 4021/fcgiwrap
- ps -ef | grep "fcgi"
- nobody 4021 1 0 18:34 ? 00:00:00 /usr/local/bin/fcgiwrap
注意配置文件中是以nobody身份运行的
6. 配置nginx
- location ~ .*\.cgi$
- {
- fastcgi_pass 192.168.1.10:10000;
- include fcgi.conf;
- }
配置文件fcgi.conf和php公用为:
- vi fcgi.conf
- fastcgi_param GATEWAY_INTERFACE CGI/1.1;
- fastcgi_param SERVER_SOFTWARE nginx;
- fastcgi_param QUERY_STRING $query_string;
- fastcgi_param REQUEST_METHOD $request_method;
- fastcgi_param CONTENT_TYPE $content_type;
- fastcgi_param CONTENT_LENGTH $content_length;
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- fastcgi_param SCRIPT_NAME $fastcgi_script_name;
- fastcgi_param REQUEST_URI $request_uri;
- fastcgi_param DOCUMENT_URI $document_uri;
- fastcgi_param DOCUMENT_ROOT $document_root;
- fastcgi_param SERVER_PROTOCOL $server_protocol;
- fastcgi_param REMOTE_ADDR $remote_addr;
- fastcgi_param REMOTE_PORT $remote_port;
- fastcgi_param SERVER_ADDR $server_addr;
- fastcgi_param SERVER_PORT $server_port;
- fastcgi_param SERVER_NAME $server_name;
- # PHP only, required if PHP was built with –enable-force-cgi-redirect
- fastcgi_param REDIRECT_STATUS 200;
OK,配置完成
参考文档:http://nginx.localdomain.pl/wiki/FcgiWrap http://salogs.com/
本文出自 “linuxjcq” 博客,请务必保留此出处http://linuxjcq.blog.51cto.com/3042600/718002