This is the fifth day of my participation in the August Wen Challenge.More challenges in August

This article has been synchronized to GitHub open source project: Java Super God Path

The concept of Nginx

Nginx (” Engine X “) is a high-performance HTTP and reverse proxy server with low memory footprint and high concurrency

Powerful, in fact, nginx’s concurrency does perform better in the same type of web server, mainland China uses Nginx

The website users are: Baidu, JINGdong, Sina, netease, Tencent, Taobao and so on.

Nginx as a Web server

Nginx can serve as a Web server for static pages and also supports dynamic CGI languages such as Perl and PHP

And so on. But Java is not supported. Java programs can only be completed in conjunction with Tomcat. Nginx was developed specifically for performance optimization,

Performance is the most important consideration, the implementation is very focused on efficiency, can withstand the test of high load, there are reports that can support high

Up to 50,000 concurrent connections. (lnmp.org/nginx.html)

Forward agent

Nginx can not only act as a reverse proxy to achieve load balancing. It can also be used as a forward proxy for Internet access and other functions.

Forward proxy: If you think of the Internet outside the LAN as a huge repository of resources, clients in the LAN need to visit

If you want to access the Internet, you need to access it through a proxy server. This proxy service is called a forward proxy.

The reverse proxy

Reverse proxy, in fact, the client is not aware of the proxy, because the client does not need any configuration to access, we only

The request needs to be sent to the reverse proxy server, which selects the target server to obtain the data after returning

In this case, the reverse proxy server and the target server are one external server and the proxy server is exposed

Address that hides the IP address of the real server.

Load balancing

The client sends multiple requests to the server, which processes the requests, some of which may interact with the database

After the server finishes processing, it returns the result to the client.

This architectural pattern is suitable for early systems with relatively few concurrent requestsCopy the code

This is low. However, with the continuous growth of the amount of information, the rapid growth of the volume of visits and data, and the complexity of the system business

Degree of increase, this architecture will cause the server corresponding client requests increasingly slow, especially when the amount of concurrent, but also easy

The server crashes. This is obviously due to server performance bottlenecks, so what can be done to solve this problem

Condition?

The first thing that comes to mind is to upgrade the server configuration, such as increasing CPU execution frequency, increasing memory, and so onCopy the code

The physical performance of the device to solve this problem, but we know that Moore’s Law is increasingly ineffective, hardware performance has been unable to improve

To meet the increasing demand. The most obvious example is the instant traffic of a hot product on Tmall’s Singles’ Day

Is extremely large, so similar to the above system architecture, the machine is added to the existing top physical configuration, is not

There is enough for demand. So what to do?

In the above analysis we have removed the solution of increasing the physical configuration of the server, that is, solving the problem verticallyCopy the code

How about scaling the number of servers horizontally? This is where the concept of clustering comes in, a single server solution

No, we increase the number of servers and distribute requests to different servers, instead of concentrating requests on a single server we distribute requests to multiple servers and distribute the load to different servers, which is what we call load balancing

Dynamic and static separation

In order to speed up the resolution of the website, dynamic pages and static pages can be resolved by different servers to speed up the resolution

Degrees. Reduce the stress of a single server.

This article has been synchronized to GitHub open source project: The Way to Java super God more Java related knowledge, welcome to visit!