Another method is to implement nginx urlhash.

Source: Internet
Author: User
The NginxHttpUpstreamRequestHashModule method is used to increase or reduce all hash errors caused by machines. Therefore, after a period of careful consideration, I feel that you have to manually develop and implement urlhash rules, then, the location tag or if Syntax of nginx is used to achieve more flexibility, operability, and availability.

Use NginxHttpUpsTrEamRequestHashMoDuIt is quite worrying about the problem of all hash disorder caused by adding or reducing machines in the way of le. So after some time of careful consideration, I feel that I have to manually develop and implement url hash rules, then use nginx loCatIon tag or if syntax to achieve more flexible, operability and availability will be greatly enhanced. However, the configuration is a little complicated and requires support from the program.

To use this environment, you need to consider the link form. The link form cannot be/xxx. jsp?Id= 1? Otherwise, the processing will be complicated and re needs to be used.WriteChange the url in this form to/1/1.html. The purpose of adding a level-1 directory in it is to use the location tag. For pure static pages or images, there are generally self-contained directory rules.

First, we should formulate a link partitioning rule, which is a little different from the file directory partitioning rule. It does not need to consider the number of files in the folder, this rule is designed to accommodate enough servers! Generally, if the id is of the balanced type, you only need to separate 26 letters and 10 digits to accommodate 36 cache servers. This is enough. If it is a digital id, take the number id0, And you can support 100 caches, Which is exaggerated enough. Generally, it is enough to support 10 servers and the configuration is easier.

With this directory rule, you can use the nginx syntax to write the configuration.

First, create a bunch of upstreams. If it is an even number, the theory can be more balanced.

Upstream {
Server 127.0.0.1: 3121;
}

Upstream B {
Server 127.0.0.1: 3122;
}

# Configure an all object to be compatible with the remaining pages without hash, such as the homepage
Upstream all {
Server 127.0.0.1: 3121;
Server 127.0.0.1: 3122;
}

1. allocated by/a/, use location

Location ~ */A | B | c | d | e | f | g | h | I | j | k | l | m | n | o | p | q | r /{
Proxy_pass http: //;
}

Location ~ */S | t | u | v | w | x | y | z | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0/ {
Proxy_pass http: // B;
}

Location /{
Proxy_pass http: // all;
}

2. You can use the if statement to determine if you do not want to change the connection rules.

Location /{
Proxy_pass http: // all;
If ($ request_uri ~ */Page _ (a | B | c | d | e | f | g | h | I | j | k | l | m | n | o | p | q | r) /){
Proxy_pass http: //;
}
If ($ request_uri ~ */Page _ (s | t | u | v | w | x | y | z | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0) /){
Proxy_pass http: // B;
}
}

After adding a new server, you need to modify the configuration and manually split the files of some directory rules. The remaining files still access the original server, which will not cause too serious impact.

In this configuration, a single page with a large access volume, such as the home page, has a large access volume and a small capacity, so it is impossible to generate a Disaster Tolerance problem. Using the round robin method will be much better in terms of availability than originally assigning a dead cache.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.