Reference: http://github.tiankonguse.com/blog/2015/01/19/cgi-nginx-three/
Then do it again, and then according to the memory of the written, not clear there are no errors and omissions of the steps, hope to comment a lot of exchanges ...
Build the Environment
Installation: Nginx, spawn-fcgi, fastcgi, Fcgiwrap
Nginx
sudo Install Nginx-full
spawn-fcgi
git clone https://Github.com/lighttpd/spawn-fcgi.git
./autogen.sh
./configure
Makeinstall
FastCGI
When installing FASTCGI, the EOF error can include header files in Include/fcgio.h Cstdio
wget http://www.fastcgi.com/dist/fcgi.tar.gztar -zxvf fcgi. Tar . gz. /Configuremakesudomakeinstall
Fcgiwrap
git clone https://github.com/gnosek/fcgiwrap.git./Configuremakesudo Make Install
Configuring the Environment
Configure Nginx
Vim/etc/nginx/sites-enabled/default
The whole file changed to this.
Server {Listen the ; server_name nextbin.com; Location/{root/home/zebin/nginx/htdoc/; Index index.html index.htm; Try_files $uri $uri/ =404; } Location~ ^/cgi-bin/.*$ {#cgi path:/home/zebin/nginx/cgi-bin/Root/home/zebin/nginx/; Fastcgi_pass127.0.0.1:9000; #configure Path:/etc/nginx/fastcgi.conf #include fastcgi.conf; Include Fastcgi_params; } }
Configure the Hosts
Vim/etc/hosts
Additional
127.0. 0.1 nextbin.com
Configure library file Links
sudo Ln -s/usr/local/lib/libfcgi.so. 0.0. 0 /usr/local/lib/libfcgi.so. 0 sudo Ln -s/usr/local/lib/libfcgi.so. 0.0. 0 /usr/lib/libfcgi.so. 0 sudo Ln -s/usr/local/lib/libfcgi.so. 0.0. 0 /usr/lib64/libfcgi.so. 0
Test CGI
Write the CGI program after compiling the executable program in the appropriate directory (such as/home/zebin/nginx/cgi-bin/demo)
#include"fcgi_stdio.h"#include<stdlib.h>intMainintargcChar*argv[]) { intCount =0; while(Fcgi_accept () >=0) {printf ("content-type:text/html\r\n" "\ r \ n" "<title>fastcgi hello!</title>" "" "Request number%d running on host <i>%s</i>\n", ++count, getenv ("server_name")); } return 0;}Demo.cpp
Compiling: g++ demo.cpp-lfcgi-o Demo
Load Fcgi-application
Ten- F /usr/local/sbin/fcgiwrap
Browser access to Nextbin.com/cgi-bin/demo is successful
========= Summary =========
Some commands to use.
PS grep -tLn --help
Toss a day finally build up. I've only tried lnmp before.
1. The database is not yet in use and needs to be supplemented
2. The relationship between spawn-fcgi, Fcgiwrap and fastcgi is unclear and needs to be understood
3. No contact with the information transmission, pending construction
Nginx+fastcgi+c/cpp