Introduction to Nginx's modular architecture

(*-*)浩
Release: 2019-11-27 13:12:32
Original
2914 people have browsed it

Introduction to Nginx's modular architecture

Nginx’s modular architecture

The internal structure of Nginx is composed of a core part and a series of It is composed of functional modules. (Recommended learning: nginx use)

This division is to make the function of each module relatively simple, easy to develop, and also convenient for functional expansion of the system. For ease of description, we will use Nginx core below to refer to the core functional parts of Nginx.

Nginx provides the basic functions of the Web server, as well as the Web service reverse proxy and Email service reverse proxy functions.

Nginx core implements the underlying communication protocol, builds a basic runtime environment for other modules and the Nginx process, and builds a collaboration basis for other modules. In addition, most of the protocol-related or application-related functions are implemented in these modules.

Module Overview

Nginx organizes each functional module into a chain. When a request arrives, the request passes through some or all modules on this chain in turn. for processing. Each module implements a specific function.

For example, a module that implements request decompression, a module that implements SSI, a module that implements communication with the upstream server, and a module that implements communication with the FastCGI service.

There are two special modules. They are located between Nginx core and various functional modules. These two modules are the http module and the mail module.

These two modules implement another layer of abstraction on top of Nginx core to handle events related to the HTTP protocol and Email-related protocols (SMTP/POP3/IMAP), and ensure that these events can be processed correctly Call some other function modules sequentially.

Currently the HTTP protocol is implemented in the http module, but it may be stripped into a separate module in the future to extend Nginx to support the SPDY protocol.

Classification of modules

Nginx modules can basically be divided into the following types according to their functions:

event module: Establishes a framework for event processing mechanisms independent of the operating system, and provides processing of specific events. Including ngx_events_module, ngx_event_core_module and ngx_epoll_module etc. The specific event processing module used by Nginx depends on the specific operating system and compilation options.

phase handler: This type of module is also directly called the handler module. Mainly responsible for processing client requests and generating content to be responded to, such as the ngx_http_static_module module, which is responsible for processing client static page requests and preparing corresponding disk files for response content output.

output filter: Also known as the filter module, it is mainly responsible for processing the output content and can modify the output. For example, you can add a predefined footbar to all output HTML pages, or replace the URL of the output image.

upstream: The upstream module implements the reverse proxy function, forwards the real request to the back-end server, reads the response from the back-end server, and sends it back to the client. The upstream module is a special handler, except that the response content is not actually generated by itself, but is read from the back-end server.

load-balancer: The load balancing module implements a specific algorithm and selects a server among many back-end servers as the forwarding server for a certain request.

The above is the detailed content of Introduction to Nginx's modular architecture. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!