spawn-fcgi运行fcgiwrap

时间:2022-07-01 14:36:29

http://linuxjcq.blog.51cto.com/3042600/718002

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://linuxjcq.blog.51cto.com/3042600/718002

1. 下载spawn-fcgi并安装

  1. http://download.lighttpd.net/spawn-fcgi/releases-1.6.x/spawn-fcgi-1.6.3.tar.gz -P /usr/local/src
  2. tar zxvf /usr/local/src/spawn-fcgi-1.6.3.tar.gz -P /usr/local/src
  3. cd /usr/local/src/spawn-fcgi-1.6.3
  4. ./configure
  5. make
  6. # 复制spawn-fcgi到/usr/local/bin/
  7. cp spawn-fcgi /usr/local/bin

2. 下载并安装fcgi库

  1. wget http://fastcgi.com/dist/fcgi-2.4.0.tar.gz -P /usr/local/src
  2. tar zxvf /usr/local/src/fcgi-2.4.0.tar.gz -C /usr/ocal/src
  3. cd /usr/local/src/fcgi-2.4.0
  4. ./configure
  5. make
  6. make install

编译过程有报错

  1. error: 'EOF' was not declared in this scope

解决办法:在include/fcgio.h文件中加上#include <cstdio>

  1. vi include/fcgio.h
  2. #include <iostream>
  3. # 添加下行
  4. #include <cstdio>

3. 安装fcgiwrap

  1. wget https://download.github.com/gnosek-fcgiwrap-1.0.3-4-g58ec209.tar.gz -P /usr/locl/src
  2. tar zxvf /usr/local/src/gnosek-fcgiwrap-1.0.3-4-g58ec209.tar.gz -P /usr/local/src
  3. cd /usr/local/src/gnosek-fcgiwrap-58ec209
  4. autoreconf -i
  5. export ac_cv_func_malloc_0_nonnull=yes
  6. ./configure
  7. make
  8. # 复制fcgiwrap
  9. cp fcgiwrap /usr/local/bin

4. 创建启动和管理脚本

  1. vi /etc/rc.d/init.d/cfcgi
  2. #!/bin/bash
  3. # cfcgi – this script starts and stops the fcgiwrap instance
  4. #
  5. # chkconfig: – 96 28
  6. # description: cfcgi
  7. # processname: cfcgi
  8. RETVAL=0
  9. case "$1" in
  10. start)
  11. echo "Starting fastcgi"
  12. /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
  13. RETVAL=$?
  14. ;;
  15. stop)
  16. echo "Stopping fastcgi"
  17. killall -9 fcgiwrap
  18. RETVAL=$?
  19. ;;
  20. restart)
  21. echo "Restarting fastcgi"
  22. killall -9 fcgiwrap
  23. /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
  24. RETVAL=$?
  25. ;;
  26. *)
  27. echo "Usage: c-fastcgi {start|stop|restart}"
  28. exit 1
  29. ;;
  30. esac
  31. exit $RETVAL

这个脚本是salogs.com中的,直接拿来用了

添加为服务

  1. chmod 0755 /etc/rc.d/init.d/cfcgi
  2. chown root:root /etc/rc.d/init.d/cfcgi
  3. chkconfig –add cfcgi
  4. chkconfig cfcgi on

5. 启动

  1. service cfcgi start

检验下:

  1. netstat -tlnp | grep "fcgiwrap"
  2. tcp 0 0 192.168.1.10:10000 0.0.0.0:* LISTEN 4021/fcgiwrap
  3. ps -ef | grep "fcgi"
  4. nobody 4021 1 0 18:34 ? 00:00:00 /usr/local/bin/fcgiwrap

注意配置文件中是以nobody身份运行的

6. 配置nginx

  1. location ~ .*\.cgi$
  2. {
  3. fastcgi_pass 192.168.1.10:10000;
  4. include fcgi.conf;
  5. }

配置文件fcgi.conf和php公用为:

  1. vi fcgi.conf
  2. fastcgi_param GATEWAY_INTERFACE CGI/1.1;
  3. fastcgi_param SERVER_SOFTWARE nginx;
  4. fastcgi_param QUERY_STRING $query_string;
  5. fastcgi_param REQUEST_METHOD $request_method;
  6. fastcgi_param CONTENT_TYPE $content_type;
  7. fastcgi_param CONTENT_LENGTH $content_length;
  8. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  9. fastcgi_param SCRIPT_NAME $fastcgi_script_name;
  10. fastcgi_param REQUEST_URI $request_uri;
  11. fastcgi_param DOCUMENT_URI $document_uri;
  12. fastcgi_param DOCUMENT_ROOT $document_root;
  13. fastcgi_param SERVER_PROTOCOL $server_protocol;
  14. fastcgi_param REMOTE_ADDR $remote_addr;
  15. fastcgi_param REMOTE_PORT $remote_port;
  16. fastcgi_param SERVER_ADDR $server_addr;
  17. fastcgi_param SERVER_PORT $server_port;
  18. fastcgi_param SERVER_NAME $server_name;
  19. # PHP only, required if PHP was built with –enable-force-cgi-redirect
  20. fastcgi_param REDIRECT_STATUS 200;

OK,配置完成

参考文档:http://nginx.localdomain.pl/wiki/FcgiWrap http://salogs.com/

本文出自 “linuxjcq” 博客,请务必保留此出处http://linuxjcq.blog.51cto.com/3042600/718002