How many series does Nginx know (1)

Original: How many series does Nginx know (1)

table of Contents

1 Introduction

2. Installation

3. Detailed configuration file

4. Working principle

5. Hosting .NET Core projects under Linux

6. Load balancing of .NET Core project under Linux

7. Nginx + Keepalived high availability for .NET Core project under Linux (master-slave mode)

8. .NET Core project Nginx + Keepalived high availability under Linux (dual master mode)

9. LVS + Keepalived + Nginx high availability cluster for .NET Core project under Linux

10. Build a static server

11. Log analysis

12. Optimization strategy

13. Summary

 

1 Introduction

This series mainly shares how we install Nginx to high-availability deployment. Nginx is no stranger to us. Most people use Nginx in projects, and each project uses Nginx to a different degree. The two most frequently used functions of Nginx are reverse proxy and load balancing. We will also focus on sharing and introducing these two functions.

 

2. What is it?

Nginx was designed and developed by Russian Igor Sysoev. The development work began in 2002 and the first public release was on October 4, 2004.
The official website is: http://nginx.org/  . It is a free and open source high-performance HTTP proxy server and reverse proxy server (Reverse Proxy) product. At the same time, it can also provide IMAP / POP3 mail proxy service and other functions. Its high concurrency performance is very good, the official test can support 50,000 concurrency; runtime memory and CPU occupancy rate is low, the configuration is simple, easy to use, and the operation is very stable.

As of December 2019, almost 1 in 3 websites in the world uses Nginx.

 

3. What can be done?

In the early stage of not relying on third-party modules, Nginx's main functions are:

①, forward agent

The forward proxy is on the user side. For example, if we need to visit some foreign websites, we may need to purchase VPN. And vpn is set in our user's browser (not on the remote server), the browser first accesses the vpn address, the vpn address forwards the request, and finally returns the request result in the same way.

 

 

②, reverse proxy

When the client sends a request to the server, it will first pass through the Nginx server, and the server will distribute the request to the corresponding WEB server. The forward proxy is a proxy client, and the reverse proxy is a proxy server. Nginx provides reverse proxy services by using regular expressions for related configurations, adopting different forwarding strategies, and the configuration is quite flexible. When forwarding a request, you don't need to care about the network environment at all, you can specify any IP address and port number, or other types of connections, requests, etc.

 
 

③, load balancing

When the number of website visits reaches a certain level, and a single server cannot meet the user's request, you need to use multiple server clusters to use nginx as a reverse proxy. And multiple servers can share the load evenly, and no server will be idle because of a high server load and downtime.

 


④, dynamic and static separation

In Web development, generally speaking, dynamic resources actually refer to those background resources, while static resources refer to HTML, JavaScript, CSS, img and other files.
Generally speaking, you need to separate dynamic resources from static resources and deploy static resources on Nginx. When a request comes, if it is a request for static resources, you can directly get resources under the static resource directory configured by nginx. It is a request for dynamic resources. Nginx uses the principle of reverse proxy to forward the request to the background application for processing, so as to achieve dynamic and static separation.
After the front-end and back-end separation is used, the access speed of static resources can be greatly improved. At the same time, the parallel development of front-end and back-end development can effectively improve the development time during the development process, and can also reduce the joint debugging time.

 

 

4. Why choose Nginx?

 

①, faster

On the one hand, under normal circumstances, a single request will get a faster response; on the other hand, during peak periods (such as tens of thousands of concurrent requests), Nginx can respond to requests faster than other web servers.

 

②, high scalability

The design of Nginx is extremely extensible. It is completely composed of multiple modules with different functions, different levels, different types and extremely low coupling. Therefore, when you fix a bug or upgrade a certain module, you can focus on the module itself without having to care about the other. And in the HTTP module, an HTTP filter module is also designed: after a normal HTTP module processes the request, there will be a series of HTTP filter modules to reprocess the result of the request. In this way, when we develop a new HTTP module, not only can use different levels or different types of modules such as HTTP core module, events module, log module, but also can reuse a large number of existing HTTP filter modules intact . This excellent design with low coupling has created Nginx's huge third-party modules. Of course, public third-party modules are also as easy to use as the officially released modules.
Nginx's modules are all embedded in binary files for execution, whether they are officially released modules or third-party modules. This allows third-party modules to have extremely excellent performance and take full advantage of Nginx's high concurrency features. Therefore, many high-traffic websites tend to develop custom modules that meet their own business characteristics.

 

③, high reliability

High reliability is the most basic condition for us to choose Nginx, because the reliability of Nginx is obvious to everyone. Many high-traffic websites use Nginx on the core server on a large scale. The high reliability of Nginx comes from the excellent design of its core framework code and the simplicity of module design; in addition, the commonly used modules provided by the official are very stable, each worker process is relatively independent, and the master process can be fast when one worker process fails "Pull up" the new worker subprocess to provide services.

 

④, low memory consumption

In general, 10,000 inactive HTTP Keep-Alive connections consume only 2.5MB of memory in Nginx, which is the basis for Nginx to support highly concurrent connections.

 

⑤, single machine supports more than 100,000 concurrent connections

This is a very important feature! With the rapid development of the Internet and the exponential growth of the number of Internet users, major companies and websites need to cope with massive concurrent requests. A server that can withstand more than 100,000 concurrent requests during the peak period will undoubtedly be popular. In theory, the upper limit of concurrent connections supported by Nginx depends on memory, and 100,000 is far from capped.

 

⑥ Hot deployment

The separate design of the master management process and the worker process allows Nginx to provide hot deployment, that is, it can upgrade the executable file of Nginx under the premise of 7 × 24 hours of uninterrupted service. Of course, it also supports functions such as updating configuration items and replacing log files without stopping the service.

 

⑦ 、 The most free BSD license agreement

This is a powerful driving force for Nginx to develop rapidly. The BSD license agreement not only allows users to use Nginx for free, it also allows users to directly use or modify the Nginx source code in their own projects and then publish it. This has attracted countless developers to continue to contribute their wisdom to Nginx

 

5. What are the advantages and disadvantages?

  advantage:

    ①, working on the 7th layer of the network, supporting Rewrite rewriting, you can do some shunting strategies for http applications, such as domain names and directory structures, its regular rules are more powerful and flexible than HAProxy, which is also its current wide One of the main reasons for the popularity, Nginx alone can use more occasions than LVS.

    ② Support high concurrent links, the official test Nginx can support 50,000 concurrent connections, the actual production environment can support 20,000 to 40,000 concurrent connections. .

    ③, buy F5BIG-IP, NetScaler and other hardware load balancing switches, need more than 100,000 to several hundred thousand yuan, and Nginx is open source software, using the 2-clause BSD-like protocol, free trial, and can be used for commercial purposes .

      The BSD open source agreement is an agreement that gives users great freedom. The agreement states that the source code can be freely used and modified, and the modified code can also be released as open source or special software.

    ④ The configuration file is very simple and easy to understand.

    ⑤, built-in health check function, if a Web server on the back end of NginxProxy is down, it will not affect the front-end access.

    ⑥, to save bandwidth, support GZIP compression, you can add the header header of the browser's local cache.

    ⑦, high stability, used for reverse proxy, the probability of downtime is minimal.

    ⑧, support hot deployment, Nginx supports hot deployment, its automatic is particularly easy, and, almost 7 days * 24 hours of uninterrupted operation, even if it does not need to be restarted for several months, it can also provide uninterrupted service In this case, upgrade the software version.

 

  Disadvantages:

    ①, the scope of adaptation is small, and can only support http, https, and email protocols.

    ② The health check of the back-end server only supports the detection through the port, does not support the detection through the url, does not support the direct maintenance of the Session, but can be solved by ip_hash.

 

6. Reference documents

  Nginx Official Homepage (English)

  Nginx Chinese network

  Nginx Chinese document

Guess you like

Origin www.cnblogs.com/lonelyxmas/p/12688682.html