cat /proc/version;
Linux version 3.10.0-862.el7.x86_64(builder@kbuilder.dev.centos.org)(gcc version 4.8.520150623(Red Hat 4.8.5-28)(GCC)) #1SMP Fri Apr 2016:44:24UTC2018
b. 也可根据Nginx版本号源码自行编译安装,如果有提示依赖包有缺失可根据错误提示安装相依依赖包即可(示例仅供参考),如果依赖包找不到路径配置时添加路径即可
wget https://nginx.org/download/nginx-1.22.0.tar.gz;
tar -zxvf nginx-1.22.0.tar.gz;
cd nginx-1.22.0;
sudo yum install pcre openssl openssl-devel;./configure --with-openssl=/usr/lib64/openssl;
sudo make && sudo make install;
3. 安装spawn-fcgi,并把可执行文件拷贝到Nginx的可执行文件目录下,稍后启动
wget http://download.lighttpd.net/spawn-fcgi/releases-1.6.x/spawn-fcgi-1.6.4.tar.gz;
tar -zxvf spawn-fcgi-1.6.4.tar.gz;
cd spawn-fcgi-1.6.4;./configure
sudo cp spawn-fcgi /usr/local/nginx/sbin
wget https://github.com/FastCGI-Archives/fcgi2/archive/refs/heads/master.zip;
unzip master.zip;
cd fcgi2-master;./autogen.sh;./configure;
sudo make && sudo make install;
cd examples;
g++ echo.c -o echo -lfcgi;
/*
* echo.c --
*
* Produce a page containing all FastCGI inputs
*
*
* Copyright (c) 1996 Open Market, Inc.
*
* See the file "LICENSE.TERMS" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
*/
#include "fcgi_config.h"
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef _WIN32
#include <process.h>
#else
extern char **environ;
#endif
#include "fcgi_stdio.h"staticvoidPrintEnv(char *label, char **envp){printf("%s:<br>\n<pre>\n", label);for(;*envp !=NULL; envp++){printf("%s\n",*envp);}printf("</pre><p>\n");}
int main(){
char **initialEnv = environ;
int count =0;while(FCGI_Accept()>=0){
char *contentLength =getenv("CONTENT_LENGTH");
int len;printf("Content-type: text/html\r\n""\r\n""<title>FastCGI echo</title>""<h1>FastCGI echo</h1>\n""Request number %d, Process ID: %d<p>\n",++count,getpid());if(contentLength !=NULL){
len =strtol(contentLength,NULL,10);}else{
len =0;}if(len <=0){printf("I am bianbian.<p>\n");}else{
int i, ch;printf("Standard input:<br>\n<pre>\n");for(i =0; i < len; i++){if((ch =getchar())<0){printf("Error: Not enough bytes received on standard input<p>\n");break;}putchar(ch);}printf("\n</pre><p>\n");}PrintEnv("Request environment", environ);PrintEnv("Initial environment", initialEnv);}/* while */return0;}
5. 启动echo程序
a. 在nginx目录下创建fastcgibin, 在哪里无所谓,只要启动路径即可,并拷贝上面的echo程序到fastcgibin下
cd /usr/local/nginx/;
sudo mkdir fastcgibin;
cd fastcgibin;
sudo cp ~/fcgi2-master/examples/echo ./;
sudo /usr/local/nginx/sbin/spawn-fcgi -a 127.0.0.1-p 7000-f ./echo -F1;
b. 服务已启动,还需要配置nginx_conf,修改location把前端请求参数转发到cgi进程上面进行业务处理,参考注释的location即可
location ~/ttl/{
fastcgi_pass 127.0.0.1:7000;
fastcgi_index index.cgi;
fastcgi_param SCRIPT_FILENAME/scripts$fastcgi_script_name;
include fastcgi_params;}