In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
1. Working principle of Nginx
Nginx consists of kernels and modules.
Nginx itself actually does very little work, when it receives a HTTP request, it simply maps the request to a location block by looking up the configuration file, and the instructions configured in this location will start different modules to complete the work, so the module can be regarded as the real labor of Nginx.
Instructions in a location usually involve a handler module and multiple filter modules (of course, multiple location can reuse the same module). The handler module is responsible for processing the request and completing the generation of the response content, while the filter module processes the response content. The modules developed by users according to their own needs belong to third-party modules. It is with the support of so many modules that the function of Nginx is so powerful.
The module of Nginx is divided into core module, basic module and third-party module.
Focus (interview only)
Core modules: HTTP module, EVENT module and MAIL module;
Basic modules: HTTP Access module, HTTP FastCGI module, HTTP Proxy module and HTTP Rewrite module
Third-party modules: HTTP Upstream Request Hash module, Notice module and HTTP Access Key module.
Nginx modules are functionally divided into the following three categories:
Handlers (processor module): this kind of module processes requests directly and performs operations such as outputting content and modifying headers information. Generally speaking, there can be only one Handlers processor module; Filters (filter module): this kind of module mainly modifies the output of other processor modules, which is finally output by Nginx; Proxies (proxy class module): such modules are modules such as HTTP Upstream of Nginx, which mainly interact with some back-end services such as FastCGI to achieve service proxy and load balancing functions.
2. The process model of Nginx. In terms of working mode, Nginx can be divided into two modes: single-process and multi-process.
In the single working process mode, in addition to the main process, there is also a working process, which is single-threaded;
In multi-worker process mode, each worker process contains multiple threads. Nginx defaults to single worker process mode.
After Nginx starts, there will be one master process and multiple worker processes.
The master process is mainly used to manage the worker process, which mainly includes receiving signals from the outside world, sending signals to each worker process, monitoring the running status of the worker process, and automatically restarting the new worker process when the worker process exits (under abnormal circumstances). The master process acts as the interactive interface between the whole process group and the user and monitors the process at the same time. It does not need to deal with network events and is not responsible for business execution. It will only manage worker processes to restart services, smooth upgrades, change log files, and take effect in real time.
Operation principle of 3.Nginx+FastCGI
Nginx does not support direct calls or parsing of external programs, and all external programs (including PHP) must be called through the FastCGI interface. The FastCGI interface is socket under Linux (this socket can be either a file socket or an ip socket). In order to call a CGI program, wrapper also needs a wrapper of FastCGI (wrapper can be understood as a program used to start another program), and this wrapper is bound to a fixed socket, such as a port or a file socket. When Nginx sends the CGI request to the socket, through the FastCGI interface, wrapper receives the request, and then Fork (derives) a new thread, which calls the interpreter or external program processing script and reads the returned data; then wrapper passes the returned data through the FastCGI interface, along the fixed socket to Nginx; and finally the Nginx sends the returned data (html page or picture) to the client.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.