Nginx Module Overview - dry goods share!

Nginx works:

Nginx by the kernel and modules

1.Nginx itself do little actual work, when it received an HTTP request, it is only by looking up the configuration file to map the request to a location block, and each instruction in this location will be configured in different start modules to do the work, so the module can be seen as Nginx real labor workers.
2. The location of a generally involves a command handler module and a plurality of filter modules (of course, a plurality of location can be shared with the same module). handler module is responsible for handling requests, generated in response to the completion of the content, and content filter module for processing the response. Users according to their needs module developed by third-party modules belong. It is precisely because so much support module, Nginx functions will be so powerful.

Nginx modules are divided into core modules, base modules and third-party modules from the structure:

1. Core module: HTTP module, EVENT MAIL modules and module
2. Basic modules: HTTP Access module, HTTP FastCGI module, HTTP Proxy module and HTTP Rewrite Module
3. third-party modules: HTTP Upstream Request Hash module, Notice modules and HTTP Access Key modules

The module is divided into the following three categories Nginx from the function:

1.Handlers (processor modules): These modules directly process the request, and outputs the content information and the like headers and modification operations. Handlers Usually only one processor module
2.Filters (filter module): the content of such other module of the processor module output modification operations, the final output Nginx 3.Proxies (proxy class module): These modules is the Nginx HTTP Upstream like modules, some of the main and back-end services such as FastCGI, etc. interact to achieve service proxy and load balancing capabilities.

Nginx process model into a single working process and multiple worker processes on the work of two modes:

1. In the single working process mode, in addition to the main process, there is a working process, the working process is the thread
2. In a multi-mode working processes, each process comprising a plurality of work threads. Nginx default mode for the single worker process

Nginx after the start there will be a master process and multiple worker processes:

1.master process is primarily used to manage the worker processes, mainly comprising: receiving a signal from the outside, a signal is sent to each worker process, monitor the operation status of worker processes, when the worker process exits (exceptional circumstances), it will automatically restart the new the worker process.
2.master whole process acts as a process group interaction with the user interface, while on the guardianship process. It does not handle network events, is not responsible for the implementation of the business, will only be achieved by managing worker process to restart the service, smooth upgrade, replace the log files, configuration files and other functions with immediate effect.

Nginx + FastCGI operating principle:

Nginx does not support direct calls to external programs or resolve all external programs (including PHP) must be called via FastCGI interface. FastCGI interface is a socket under Linux (This socket can be a file socket, can be ip socket). To invoke a CGI wrapper, you also need a FastCGI a wrapper (wrapper can be understood as a program used to start another program), the wrapper bound to a fixed socket, such as port or file socket. When the time Nginx CGI request to the socket through the interface FastCGI, wrapper receipt of the request, and then Fork (derive) a new thread, the external thread calls an interpreter or script program processing and returns the read data; Next wrapper FastCGI then returned via the interface data is transmitted to the fixed along Nginx Socket; Nginx finally returned data (html page or image) is sent to the client.

The operating principle in the following figure:

Here Insert Picture Description

Guess you like

Origin blog.51cto.com/14464303/2450989