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 are the characteristics of nginx

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what are the characteristics of nginx". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "what are the characteristics of nginx"?

What is 1.Nginx?

Nginx is the reverse proxy server. First of all, let's take a look at what is a proxy server. A proxy server generally refers to a server in the local area network that sends requests to the Internet through proxy services, and the proxy server generally acts on the client. Like the GoAgent,FQ artifact.

What are the characteristics of 2.Nginx?

(1) Cross-platform: Nginx can be compiled and run in most Unix like OS, and there is also a migrated version of Windows.

(2) the configuration is very simple and easy to use. Configuration style is the same as program development, divine configuration

(3) non-blocking, highly concurrent connections: when data is replicated, the first phase of the disk Iripple O is non-blocking. The official test can support 50,000 concurrent connections and reach 20,000 to 30,000 concurrent connections in the actual production environment. (this is due to the fact that Nginx uses the latest epoll model)

(4) event-driven: the communication mechanism adopts epoll model to support larger concurrent connections.

(5) master/worker structure: a master process that generates one or more worker processes

(6) small memory consumption: very small memory consumption for processing large concurrent requests. With 30 000 concurrent connections, 10 Nginx processes open consume only 150 MB of memory (15M*10=150M)

(7) low cost: Nginx is open source software and can be used free of charge. On the other hand, the purchase of hardware load balancing switches such as F5 BIG-IP and NetScaler costs more than 100,000 to hundreds of thousands of yuan.

(8) built-in health check function: if a Web server at the Nginx Proxy backend goes down, the access to the frontend will not be affected.

(9) bandwidth saving: GZIP compression is supported, and Header headers cached locally by the browser can be added.

(10) High stability: for reverse agents, the probability of downtime is minimal.

How does 3.Nginx handle a request?

First of all, when nginx starts, it parses the configuration file to get the port and ip address to listen on. Then, in the master process of nginx, initialize the socket of the monitor (create socket, set options such as addrreuse, bind to the specified ip port, and then listen), and then fork (an existing process can call the fork function to create a new process. A new process created by fork is called a child process) multiple child processes come out, and then the child processes compete for accept's new connection. At this point, the client can initiate a connection to nginx. When the client makes a three-way handshake with nginx and establishes a connection with nginx, a child process will accept successfully, get the socket of the established connection, and then create the nginx encapsulation of the connection, that is, the ngx_connection_t structure. Next, set the read-write event handler and add read-write events to exchange data with the client. Finally, the nginx or the client actively shuts down the connection, and a connection completes its mission.

Of course, nginx can also be used as a client to request data from other server (such as upstream module). At this time, connections created with other server are also encapsulated in ngx_connection_t. As a client, nginx first takes a ngx_connection_t structure, then creates a socket, and sets the properties of the socket (such as non-blocking). Then, by adding read and write events, calling connect/read/write to invoke the connection, and finally closing the connection, and releasing ngx_connection_t.

Description:

When nginx is implemented, it is managed by a connection pool. Each worker process has an independent connection pool, and the size of the connection pool is worker_connections. What is stored in the connection pool here is not a real connection, it is just an array of ngx_connection_t structures of worker_connections size. In addition, nginx will store all free ngx_connection_t through a linked list free_connections. Each time a connection is obtained, it will get one from the free connection list, and then put it back into the free connection list.

Here, many people will misunderstand the meaning of the parameter worker_connections and think that this value is the maximum value that nginx can establish a connection. In fact, this value represents the maximum number of connections that can be established by each worker process, so the maximum number of connections that a nginx can make should be worker_connections * worker_processes. Of course, we are talking about the maximum number of connections. For HTTP requests for local resources, the maximum number of concurrency can be worker_connections * worker_processes, while if HTTP is used as a reverse proxy, the maximum number of concurrency should be worker_connections * worker_processes/2. Because as a reverse proxy server, each concurrency will establish a connection to the client and a connection to the back-end service, which will occupy two connections

What has 4.Nginx done?

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 module of Nginx is compiled directly into Nginx, so it belongs to static compilation mode. After starting Nginx, the module of Nginx is loaded automatically, unlike Apache, which first compiles the module into a so file, and then specifies whether to load or not in the configuration file. When parsing the configuration file, it is possible for each module of Nginx to process a request, but the same processing request can only be done by one module.

At this point, I believe you have a deeper understanding of "what are the characteristics of nginx?" you might as well come to the actual operation! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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

Internet Technology

Wechat

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

12
Report