I. installation, deployment and configuration of spawn_fastcgi .
1. Download spawn_fastcgi. https://github.com/lighttpd/spawn-fcgi
The version of 1.6.3 is used here https://github.com/lighttpd/spawn-fcgi/releases/tag/v1.6.3 2. Unzip and install (please remember to read the Readme). (1) If no
Configure, please first perform
./autogen.sh, generate Configure (2)./configure (3) make
Note: If the installation through the above is unsuccessful, try direct sudo apt-get install spawn_fastcgi3. After compiling, move the executable file to the Nginx sbin directory. CP./src/spawn-fcgi/usr/local/nginx/sbin/(CP to nginx installation directory)Note: 1.3rd step, if the copy process is prompted to find the./src/spawn-fcgi, the binary copy is found with the which spawn-fcgi;2.3rd step, if you are prompted to find/usr/local/nginx/sbin/during the copy process, create the directory manually.
two. Installation of the FASTCGI library.1. Downloadhttp://www.fastcgi.com/dist/fcgi.tar.gz (There may be a problem downloading from this, preferably in this article.)
2. $./configure $make $make InstallNote: 1. If the following error occurs during installation, add the header file #include <stdio.h> in Fcgio.cpp, and recompile.Reference Http://stackoverflow.com/questions/8833718/installing-fastcgi-dev-kit2. If make passes, but makes install error, try to use the file given in this article without the Step 1 link.
Fcgio.cpp:In destructor ' virtual fcgi_streambuf::~fcgi_streambuf () ':
Fcgio.cpp:50:14:error: ' EOF ' is not declared in this scope
Fcgio.cpp:In member function ' virtual int fcgi_streambuf::overflow (int) ':
Fcgio.cpp:70:72:error: ' EOF ' is not declared in this scope
Fcgio.cpp:75:14:error: ' EOF ' is not declared in this scope
Fcgio.cpp:In member function ' virtual int fcgi_streambuf::sync () ':
Fcgio.cpp:86:18:error: ' EOF ' is not declared in this scope
Fcgio.cpp:87:41:error: ' EOF ' is not declared in this scope
Fcgio.cpp:In member function ' virtual int fcgi_streambuf::underflow () ':
Fcgio.cpp:113:35:error: ' EOF ' is not declared in this scope
MAKE[2]: * * * [Fcgio.lo] Error 1
MAKE[2]: Leaving directory '/home/lucasysfeng/workspace/web/download/nginx_spawn_fcgi_install_package/ Fcgi-2.4.1-snap-0311112127/libfcgi '
MAKE[1]: * * * [all-recursive] Error 1
MAKE[1]: Leaving directory '/home/lucasysfeng/workspace/web/download/nginx_spawn_fcgi_install_package/ fcgi-2.4.1-snap-0311112127 '
Make: * * * [ALL] Error 2
three. Demo program.1. demo.cc is as follows:
#include <fcgi_stdio.h> #include <stdlib.h> #include <unistd.h>int main () { int count = 0; while (fcgi_accept () >= 0) { printf ("content-type:text/html\r\n" "\ r \ n" "" "" FastCGI hello! " " Request number%d running on host%s " Process ID:%d\n", ++count, getenv ("SERVER_NAME"), Getpid ()); } return 0;}
2. Compile.
g++ demo.cc-o demo-lfcgi?
Note: 1. If the compilation does not pass, it may be the library
-lfcgi?Not found, that is <
two. Installation of the FASTCGI library.> has problem 2. Run the executable directly to see if it works. If there is a missing library libfcgi.so.0, you need to manually
/usr/local/lib/libfcgi.so.0The library establishes a link to the/usr/lib/directory:
ln-s/usr/local/libfcgi.so.0/usr/lib/(or add So's library path to the/etc/ld.so.conf,
and perform ldconfig update)
four. Demo release.1) Move the CGI executable to the Nginx installation directory/usr/local/nginx/cgibin (the folder does not exist and you create it yourself)
CP ***/demo/usr/local/nginx/cgibin2) Start the SPAWN-FCGI management process and bind the server IP and port (
do not coincide with Nginx's listening port)
/usr/local/nginx/sbin/spawn-fcgi-a 127.0.0.1-p 8088-f/usr/local/nginx/cgibin/demo
Check if Port 8088 is successful: Netstat-na | grep 8088? 3) Change
nginx.confConfiguration file (
or a/etc/nginx/sites-available/default .), let Nginx forward the request
Add a configuration in the child node of the HTTP node-"Server section" point
Location ~ \.cgi$ {
Fastcgi_pass 127.0.0.1:8088;
Fastcgi_index index.cgi;
Fastcgi_param script_filename Fcgi$fastcgi_script_name;
include Fastcgi_params;
}
4) Restart Nginx or reload the configuration file
sudo service nginx restart
5) Open a browser to access it
http://localhost/demo.cgi
Web (v)---spawn-fastcgi