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 ways that Nginx's upstream supports allocation?

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

Share

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

This article focuses on "what are the ways in which Nginx's upstream support is allocated". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what are the ways in which Nginx's upstream support is allocated?"

1. Polling (default)

Each request is assigned to a different backend server one by one in chronological order. If the backend server down is dropped, it can be automatically eliminated.

2 、 weight

Specify the polling probability. The weight is proportional to the access ratio, which is used in the case of uneven performance of the backend server.

For example:

Upstream bakend {

Server 192.168.0.14 weight=10

Server 192.168.0.15 weight=10

}

3 、 ip_hash

Each request is allocated according to the hash result of accessing the ip, so that each visitor accesses a back-end server on a regular basis, which can solve the session problem.

For example:

Upstream bakend {

Ip_hash

Server 192.168.0.14:88

Server 192.168.0.15:80

}

4. Fair (third party)

Requests are allocated according to the response time of the back-end server, and priority is given to those with short response time.

Upstream backend {

Server server1

Server server2

Fair

}

5. Url_hash (third party)

Allocate requests according to the hash result of accessing url, so that each url is directed to the same backend server, which is more effective when the backend server is cached.

Example: add hash statement to upstream. Other parameters such as weight cannot be written in server statement. Hash_method is the hash algorithm used.

Upstream backend {

Server squid1:3128

Server squid2:3128

Hash $request_uri

Hash_method crc32

}

Upstream bakend {# defines the Ip and device status of load balancing devices

Ip_hash

Server 127.0.0.1:9090 down

Server 127.0.0.1:8080 weight=2

Server 127.0.0.1:6060

Server 127.0.0.1:7070 backup

Added in server where load balancing is required

Proxy_pass http://bakend/;

The status of each device is set to:

1.down indicates that the server before the order does not participate in the load for the time being.

The default 2.weight is that the larger the 1.weight, the greater the weight of the load.

3.max_fails: the number of requests allowed to fail defaults to 1. Returns the error defined by the proxy_next_upstream module when the maximum number of times is exceeded

Time to pause after 4.fail_timeout:max_fails failure.

5.backup: all other non-backup machines down or request backup machines when they are busy. So this machine will be the least stressed.

Nginx supports setting multiple groups of load balancers at the same time, which can be used by unused server.

If client_body_in_file_only is set to On, the data from client post can be recorded into a file to be used as debug.

The directory of client_body_temp_path settings record files can be set up to 3-tier directories

Location matches the URL. You can redirect or do new agent load balancing.

At this point, I believe you have a deeper understanding of "Nginx's upstream support allocation". You might as well do it in practice. 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