spawn-fcgi运行fcgiwrap

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. ./configure  
  6. make  
  7. # 复制fcgiwrap  
  8. cp fcgiwrap /usr/local/bin 

中间有报错

  
  
  
  
  1. undefined reference to rpl_malloc 

解决方法:

  
  
  
  
  1. vi config.h.in  
  2. undef malloc  
  3. # 这这行注释  
  4. /* #undef malloc */ 

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.  
  9. RETVAL=0 
  10.  
  11. case "$1" in  
  12. start)  
  13. echo "Starting fastcgi"  
  14. /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  
  15. RETVAL=$?  
  16. ;;  
  17. stop)  
  18. echo "Stopping fastcgi"  
  19. killall -9 fcgiwrap  
  20. RETVAL=$?  
  21. ;;  
  22. restart)  
  23. echo "Restarting fastcgi"  
  24. killall -9 fcgiwrap  
  25. /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  
  26. RETVAL=$?  
  27. ;;  
  28. *)  
  29. echo "Usage: c-fastcgi {start|stop|restart}"  
  30. exit 1  
  31. ;;  
  32. esac  
  33. 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;  

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

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

OK,配置完成

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

你可能感兴趣的:(职场,fcgi,休闲,spawn-fcgi,fcgiwarp)