Testing Nginx + FastCgi
Nginx + Fastcgi configuration method1. install and configure nginx1) apt-get install nginx
2) modify the default file under/etc/nginx/sites-available
# Set the homepage root/usr/share/nginx/myweb; index index.html index.htm; # modify the port listen 8880 default_server; listen [::]: 8880 default_server defaults 6only = on; # Set the fastcgi program entry location/mycgi. cgi {fastcgi_pass 127.0.0.1: 9999;-> port listened by the fastcgi Program # fastcgi_index mycgi. out; include fastcgi_params ;}
Ii. install apt-get install spawn-fcgi on the fastcgi Manager
3. The fcgi library cannot be downloaded from the official website. It is strange to see the attachment for temporary reference.
1) modify the include/fcgio. h file and append # include
2)./configure
3)./make install
4) ldconfig/usr/local/lib (default path generated by libfcgi. so)
4. Compile cgi program example Code as follows:
#include
#include
#include
#include
#include
int main(int argc, char** argv){ int count = 0; while( FCGI_Accept() >= 0 ) { printf( "Content-type:text/html\r\n\r\n" ); printf( "
Hello FastCGI !
" ); printf( " Request number = [%d]", ++count ); printf( " CGI PID: %d ", getpid() ); } return 0;}
Compile
G ++ mycgi. c-o mycgi. out-L/usr/local/lib-lfcgi
V. Start cgispawn-fcgi-a 127.0.0.1-p 9999-f/root/mycgi. out-F 3
-F indicates the number of cgi processes started. nginx will poll the access
Access http: // server: 8880 to view the cgi program output.