Nginx + fastcgi configuration method
One, Nginx installation & configuration1) apt-get Install Nginx
2) Modify the default file under/etc/nginx/sites-available
</pre><pre name= "code" class= "plain" > #设置首页root/usr/share/nginx/myweb;index index.html index.htm;# Modify Port Listen 8880 Default_server;listen [::]:8880 default_server ipv6only=on; #设置fastcgi程序入口location/mycgi.cgi { Fastcgi_pass 127.0.0.1:9999; FASTCGI program monitoring port #fastcgi_index mycgi.out; Include Fastcgi_params;}
Second, the installation of FastCGI manager spawn-fcgi apt-get Install spawn-fcgi
Third, the installation of FCGI Library did not find the official website to download, some strange, temporary reference accessories.
1) Modify Include/fcgio.h file, append # include <cstdio>
2)./configure
3)./make Install
4) ldconfig/usr/local/lib (libfcgi.so default build path)
The example code of compiling CGI program is as follows:
#include <iostream> #include <fcgi_stdio.h> #include <stdlib.h> #include <sys/types.h># Include <unistd.h>int main (int argc, char** argv) { int count = 0; while (fcgi_accept () >= 0) { printf ("content-type:text/html\r\n\r\n"); printf ("<p> Hello FastCGI! </p> "); printf ("<br/> Request number = [%d]", ++count); printf ("<br/> CGI PID:%d", getpid ()); } return 0;}
Compile
g++ Mycgi.c-o mycgi.out-l/usr/local/lib-lfcgi
Five, start cgispawn-fcgi-a 127.0.0.1-p 9999-f/root/mycgi/mycgi.out-f 3
-f Specifies the number of CGI processes to start, and nginx polls the access
You can see the output of the CGI program by accessing http://server:8880.
Test of nginx+fastcgi