Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the Nginx server architecture?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

Editor to share with you what the Nginx server architecture is, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

A brief introduction to the overall architecture of 1.Nginx

1) after Nginx starts, a main process will be generated, and one or more working processes will be generated after the main process executes a series of work.

2) when the client requests a dynamic site, the Nginx server also involves communication with the back-end server. Nginx forwards the received Web requests to the back-end server through the proxy, which processes and organizes the data.

3) in order to improve the efficiency of response to requests and reduce the pressure on the network, Nginx adopts a caching mechanism to cache the historical response data locally. Ensure fast access to cache files

2. Modularization of Nginx

Highly modular design is the architectural foundation of Nginx. Nginx strictly follows the principle of "high cohesion, low coupling". The server is designed as multiple modules, each module is an independent functional module, only responsible for its own functions.

The importance of these five modules decreases from top to bottom.

(1) Core module

The core module is an indispensable module for the normal operation of the Nginx server, just like the kernel of the operating system. It provides the most basic core services of Nginx. Such as process management, rights control, error logging, etc.

(2) Standard HTTP module

Standard HTTP modules support the functionality of standard HTTP

(3) optional HTTP module

The optional HTTP module is mainly used to extend the standard HTTP functions so that Nginx can handle some special services.

(4) Mail service module

The mail service module is mainly used for mail services that support Nginx

(5) third-party module

The purpose of the third-party module is to extend the Nginx server application and complete the functions that developers want.

Web request processing Mechanism of 3.Nginx

Architecturally speaking, the Nginx server is different. One lies in its modular design; the second and more important point lies in its mechanism for handling requests from clients. Nginx request processing mechanism combines multi-process mechanism and asynchronous non-blocking mechanism.

1) multiple processes

Multi-process mode means that whenever the server receives a client request, the server main process generates a child process to establish a connection with the client to interact with the server, until the connection is broken, the child process ends. The advantage of the multi-process approach is that the design is simple, the sub-processes are relatively independent, and the client requests are not disturbed by each other; the disadvantage is that the operating system generates a sub-process that requires operations such as memory replication, which will incur some overhead in resources and time; when there are a large number of requests, it will lead to a decline in system performance.

2) Asynchronous non-blocking

After sending a request to the receiver, the sender does not have to wait for a response and can continue other work; if the IO operation performed by the receiver when processing the request can not get the result immediately, it does not have to wait, but immediately returns to do something else. When the IO operation is completed, the receiver is notified of the completion status and result, and the receiver responds to the sender.

4. Event-driven model of Nginx server

We can see from the above that after the worker process of the Nginx server calls IO, it will do other work; when the IO call returns, it will actively notify the worker process. System calls such as select/poll/epoll are used to support this solution. These system calls are also often referred to as event-driven models, and they provide a mechanism for processes to process multiple concurrent requests at the same time, regardless of the status of IO calls. IO calls are managed entirely by the event-driven model.

As shown in the figure above, the event-driven model of Nginx consists of three basic units: event collector, event sender and event processor.

Select,poll,epoll is the mechanism of IO multiplexing. Icano multiplexing is through a mechanism that a process can monitor multiple descriptors, and once a descriptor is ready (usually read or write ready), it can tell the program to read and write accordingly. Select,poll,epoll is essentially synchronous Ibank O, because they all need to be responsible for reading and writing after the read-write event is ready, which means that the read-write process is blocked.

5. Master-Worker process processing model of Nginx server

When using the Master-Worker model, the Nginx server will involve the interaction between the main process and the worker process and the interaction between the worker process. Both types of interactions depend on the plumbing mechanism.

Master-Worker interaction

This pipeline is different from the ordinary pipeline, it is an one-way pipeline from the main process to the worker process, including the instructions issued by the main process to the worker process, the worker process ID, etc.; at the same time, the main process communicates with the outside world through signals

Worker-Worker interaction

This interaction is basically the same as the Master-Worker interaction, but through the main process. The worker processes are isolated from each other, so when the worker process W1 needs to send instructions to the worker process W2, first find the process ID of W2, and then write the correct instruction to the channel pointing to W2. W2 receives the signal and takes corresponding measures.

These are all the contents of the article "what is the Nginx server architecture?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report