This module is provided by a third party and is not included in the Nginx source release version.
Upstream_hash This module provides a simple upstream load allocation by hashing a configurable variable (for example, a request URI, an incoming HTTP header, or some combination). Examples of usage are as follows:
Upstream backend {: Server server1: Server server2;: hash $request _uri;}
Here, Nginx selects Server1 or Server2 by the URI ($ request_uri) of the hash request.
Syntax: Hash $variable Scope: Upstream Enables hashing of upstream $variable variables. Currently, the server directive cannot execute any parameters ("weight", "max_fails", etc.). Template:anchor
Hash_method
Syntax: Hash_method [CRC32 | simple] Default value: Simple Scope: Upstream The hash algorithm uses "CRC32" to take the last 15 bits of the CRC32 value and is calculated by the number of servers. (This behavior is compatible with Libmemcache.) As described below, "the" simple "hash Algorithm". Template:anchor
Hash_again
Syntax: Hash_again number Default value: 0 Scope: Upstream If the backend connection fails, the value is processed in the amount of time and a different server is selected. Increase the number to provide high availability. Template:anchor
Installation
The module is not a nginx source distribution. You can download the Request_hash module here: nginx_upstream_hash-0.2.tar.gz.
After decompression, you will need to patch to the latest Nginx source (0.5.21 version). Run the patch as follows:
: CD Nginx-0.5.21:patch-p0 </path/to/upstream/hash/directory/nginx-0.5.21.patch
Then add the following options to your nginx./configure command:
:--add-module=path/to/upstream/hash/directory
Then, run "make" and "make install" normally.
Template:anchor
The "simple" hash Algorithm
The "simple" hash algorithm is the same as used in the Nginx internal hash table. This feature is:
U_int Ngx_hash_key (U_char *data, size_t len) {: U_int I, key;: key = 0;: for (i = 0; i < len; i++) {: Key *=: key = Data[i] ;:}: Return key;}
The hash value is modulo ' d of the number of selected servers. A server index can be determined by the order in which it appears in the upstream block.
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.