Nginx+fastcgi+c/c++ Source Installation Configuration

Source: Internet
Author: User
Tags php script

Reference: http://www.cnblogs.com/xiaouisme/archive/2012/08/01/2618398.html

Since Apache has been installed before, a lot of dependent libraries are installed, and now you only need to install the following packages:

Nginx-1.4.4.tar.gz

SPAWN-FCGI-1.6.3.TAR.GZ (fastcgi process Management program)

Fcgi.tar.gz (fastcgi library and header file)
Install Nginx

# TAR-XVF/nginx-1.4.4.tar.gz.

# CD nginx-1.4.4

#./configure--prefix=/usr/local/nginx--error-log-path=/var/log/nginx/error.log--http-log-path=/var/log/nginx/ Access.log--http-fastcgi-temp-path=/var/lib/nginx/fastcgi--lock-path=/var/lock/nginx.lock--pid-path=/var/run/ Nginx.pid--with-debug--with-http_addition_module--with-http_ssl_module

# make; Make install

Installation completed, open service:

#/usr/local/nginx/sbin/nginx

Access in Browser:

Http://ip

The Welcome page appears, stating that the installation Nginx successful

Nginx detailed configuration not introduced here
Install spawn-fcgi

Nginx is a supporter of fastcgi. However, we need the next FASTCGI process Manager to launch it to execute the FASTCGI program.

Here are a few concepts to understand: Nginx is nginx,fastcgi is fastcgi, the former support the latter, but the former does not integrate the latter's function. For NGINGX, we want to configure Conf.nginx to set up how to support fastcgi. For fastcgi, the FASTCGI program we write requires a dispatcher: fastcgi process Manager, or spawn-fcgi. --purely personal understanding.

This spawn-fcgi is the FASTCGI process manager. is a subproject in the lighttpd.

# TAR-XVF/spawn-fcgi-1.6.3.tar.gz.

# CD./spawn-fcgi-1.6.3

#./configure; Make #cp./src/spawn-fcgi/usr/local/nginx/sbin/ Installation fastcgi library

# TAR-XVF/fcgi.tar.gz.

# CD./fcgi-2.4.1-snap-0311112127

#./configure;

If direct compilation will make an error, the following is handled:

# Vi./include/fcgio.h

Add the following header file:

#include <cstdio> make; Make install test

# Cd/usr/local/nginx

# mkdir Fastcgitest #cd fastcgitest

Write the following code:

#include <stdio.h>  
#include <fcgi_stdio.h>  
#include <stdlib.h>  
#include <unistd.h >  
  
//using namespace std;  
  
int main ()  
{  
    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/> Process ID:%d", getpid ());  
      
    }  
  
return 0;  
}  

Save into test1.c

Compile:

# Gcc-werror-wall./test1.c-o./test1.cgi-lfcgi-wl,-r/usr/local/lib

Start:

# sudo spawn-fcgi-a 127.0.0.1-p 9000-f/usr/local/nginx/fastcgitest/test1.cgi-f 1-p/var/log/nginx/myfastcgi

Modify the/usr/local/nginx/conf/nginx.conf and add the following in the server:

Location ~\.cgi$

{

Root fastcgitest;

Fastcgi_pass 127.0.0.1:9000;

Fastcgi_index index.cgi;

Fastcgi_param $fastcgi _script_name;

Include Fastcgi_params;

}

Reload configuration file:

#/usr/local/nginx/sbin/nginx-s Reload

Access in Browser:

http://ip/test1.cgi

several concepts of success

1. Ginx receives a CGI request, it looks at how many processes the CGI program (spawn-fcgi-f the specified parameters), and then invokes the CGI program based on the amount of concurrency.
2. The original spawn-fcgi (refer to the daemon version of spawn-fcgi in the following seven references) fork the CGI program and quit. At this point the fork CGI program's parent process ID is 1, that is, the init system process. This way, if you want concurrency, you need your fastcgi to support concurrency, google:fastcgi concurrency
3. About Php,nginx is using fastcgi to parse PHP. This is responsible for the resolution of the FASTCGI program is not much, as if 1, so this CGI can not be concurrency, but it does not matter Nginx support CGI cache ~ so PHP Web page concurrent request and fastcgi relationship is not big. In fact, you can fastcgi the role of PHP as a compiler, after compiling, PHP has a cache, and then requests do not need to run again fastcgi to parse PHP script, PHP is a bloody script ah

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.