Nginx is probably the hottest Web and reverse proxy server out there right now. It is a high-performance Web server from Russia that performs better than Apache, especially in high concurrency situations.
What other uses does it have besides load balancing? Let’s take a look.
Static proxy
Nginx is good at handling static files and is a great image and file server. By putting all static resources on Nginx, applications can be static and static and perform better.
Second, load balancing
Through reverse proxy, Nginx can realize load balancing of services, avoid single node failure of the server, and forward requests to different servers according to certain policies to achieve load effect.
Common load balancing policies are as follows:
1, polling
Requests are distributed to back-end servers in a sequential rotation that treats each server on the back-end equally, regardless of the actual number of connections to the server and the current system load.
2. Weighted polling
Different back-end servers may not have the same machine configuration and load on the current system, so they may not have the same ability to withstand stress.
Assign higher weights to machines with high configuration and low load to handle more requests; Weighted polling works well for low-configuration, high-load machines by assigning them a lower weight, reducing their system load, and ordering and weighting requests to the back end.
3. Ip_hash
According to the IP address of the client, a value is calculated through the hash function, and the size of the server list is modulo calculated with this value. The result is the serial number of the server to be accessed by the client.
The source address hash method is used for load balancing. When the list of back-end servers remains unchanged, clients with the same IP address will be mapped to the same back-end server each time for access.
4, random
Through the random algorithm of the system, a server is randomly selected for access according to the size of the list of back-end servers.
5. Least_conn (Minimum connection number Method)
Due to the backend server configuration is not the same, have fast or slow to request processing, the minimum number of connections method based on the current back-end server connection, dynamically select the current backlog connections at least one server to deal with the current request, improve the utilization efficiency of the back-end service as much as possible, will be responsible for properly to each server.
Three, the current limit
Nginx’s current limiting module is based on the leak-bucket algorithm, which is very practical in high concurrency scenarios, as shown in the following figure:
1. Set parameters
1) Limit_REq_zone is defined in the HTTP block, where $binary_remote_addr means to save the binary form of the client IP address.
2) Zone The shared memory area that defines the IP status and URL access frequency.
Zone =keyword Identifies the name of the region, followed by a colon, and the size of the region. The state information for 16000 IP addresses is about 1MB, so the zone in the example can store 160,000 IP addresses.
3) Rate Defines the maximum request Rate. The rate in the example cannot exceed 100 requests per second.
2. Set current limiting
Burst queue size, nodelay does not limit the time between individual requests.
Four, caching,
1, browser cache, static resource cache with expire.
Proxy layer cache
V. Black and white lists
1. Unlimited stream whitelist
2. Blacklist
Nginx: Static separation, load balancing, traffic limiting, caching, blacklists, etc.
Source: www.toutiao.com/i6692127248…