1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4 <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
5 <meta name="robots" content="index,nofollow">
7 <title>NginxHttpUpstreamRequestHashModule - Nginx Wiki</title>
8 <script type="text/javascript" src="/htdocs/common/js/common.js"></script>
10 <script type="text/javascript">
11 <!--// common functions
13 // We keep here the state of the search box
14 searchIsDisabled = false;
16 function searchChange(e) {
17 // Update search buttons status according to search box content.
18 // Ignore empty or whitespace search term.
19 var value = e.value.replace(/\s+/, '');
20 if (value == '' || searchIsDisabled) {
21 searchSetDisabled(true);
23 searchSetDisabled(false);
27 function searchSetDisabled(flag) {
28 // Enable or disable search
29 document.getElementById('fullsearch').disabled = flag;
30 document.getElementById('titlesearch').disabled = flag;
33 function searchFocus(e) {
34 // Update search input content on focus
35 if (e.value == 'Search') {
38 searchIsDisabled = false;
42 function searchBlur(e) {
43 // Update search input content on blur
46 e.className = 'disabled';
47 searchIsDisabled = true;
51 function actionsMenuInit(title) {
52 // Initialize action menu
53 for (i = 0; i < document.forms.length; i++) {
54 var form = document.forms[i];
55 if (form.className == 'actionsmenu') {
56 // Check if this form needs update
57 var div = form.getElementsByTagName('div')[0];
58 var label = div.getElementsByTagName('label')[0];
60 // This is the first time: remove label and do buton.
61 div.removeChild(label);
62 var dobutton = div.getElementsByTagName('input')[0];
63 div.removeChild(dobutton);
65 var select = div.getElementsByTagName('select')[0];
66 var item = document.createElement('option');
67 item.appendChild(document.createTextNode(title));
69 select.insertBefore(item, select.options[0]);
70 select.selectedIndex = 0;
79 <link rel="stylesheet" type="text/css" charset="utf-8" media="all" href="/htdocs/mentalwealth/css/common.css">
80 <link rel="stylesheet" type="text/css" charset="utf-8" media="screen" href="/htdocs/mentalwealth/css/screen.css">
81 <link rel="stylesheet" type="text/css" charset="utf-8" media="print" href="/htdocs/mentalwealth/css/print.css">
82 <link rel="stylesheet" type="text/css" charset="utf-8" media="projection" href="/htdocs/mentalwealth/css/projection.css">
85 <link rel="Start" href="/Main">
86 <link rel="Alternate" title="Wiki Markup" href="/NginxHttpUpstreamRequestHashModule?action=raw">
87 <link rel="Alternate" media="print" title="Print View" href="/NginxHttpUpstreamRequestHashModule?action=print">
88 <link rel="Appendix" title="nginx_request_hash-0.1.tar.gz" href="/NginxHttpUpstreamRequestHashModule?action=AttachFile&do=view&target=nginx_request_hash-0.1.tar.gz">
89 <link rel="Appendix" title="nginx_upstream_hash-0.2.tar.gz" href="/NginxHttpUpstreamRequestHashModule?action=AttachFile&do=view&target=nginx_upstream_hash-0.2.tar.gz">
90 <link rel="Appendix" title="nginx_upstream_hash-0.3.tar.gz" href="/NginxHttpUpstreamRequestHashModule?action=AttachFile&do=view&target=nginx_upstream_hash-0.3.tar.gz">
91 <link rel="Search" href="/FindPage">
92 <link rel="Index" href="/TitleIndex">
93 <link rel="Glossary" href="/WordIndex">
94 <link rel="Help" href="/HelpOnFormatting">
97 <body lang="en" dir="ltr">
99 <div id="header"><div id="searchform">
100 <form id="searchform" method="get" action="">
102 <input type="hidden" name="action" value="fullsearch">
103 <input type="hidden" name="context" value="180">
104 <label for="searchinput">Search:</label>
105 <input id="searchinput" type="text" name="value" value="" size="20"
106 onfocus="searchFocus(this)" onblur="searchBlur(this)"
107 onkeyup="searchChange(this)" onchange="searchChange(this)" alt="Search">
108 <br><input id="titlesearch" name="titlesearch" type="submit"
109 value="Titles" alt="Search Titles">
110 <input id="fullsearch" name="fullsearch" type="submit"
111 value="Text" alt="Search Full Text">
114 <script type="text/javascript">
115 <!--// Initialize search form
116 var f = document.getElementById('searchform');
117 f.getElementsByTagName('label')[0].style.display = 'none';
118 var e = document.getElementById('searchinput');
123 </div><div id="logo"><a href="/Main"><img src="/images/nginx-black-logo.jpg" alt="Nginx Wiki"></a></div></div>
126 <div class="sidepanel"><h1>Navigation</h1>
128 <li class="wikilink"><a href="/Main">Main</a></li><li class="wikilink"><a href="/FindPage">FindPage</a></li><li class="wikilink"><a href="/HelpContents">HelpContents</a></li><li class="current"><a href="/NginxHttpUpstreamRequestHashModule">NginxHttpUp...tHashModule</a></li>
131 <div class="sidepanel"><h1>User</h1><ul id="username"><li><a href="/NginxHttpUpstreamRequestHashModule?action=login" id="login">Login</a></li></ul></div>
133 <li><a href="http://moinmoin.wikiwikiweb.de/">MoinMoin Powered</a></li><li><a href="http://www.python.org/">Python Powered</a></li><li><a href="http://validator.w3.org/check?uri=referer">Valid HTML 4.01</a></li>
138 <div id="page" lang="en" dir="ltr">
139 <div dir="ltr" id="content" lang="en"><span class="anchor" id="top"></span>
140 <span class="anchor" id="line-2"></span><p class="line867">
141 <h1 id="head-46349e4051ab58f9d43b4e4cbe75a22812583dc1">ngx_http_upstream_hash_module</h1>
142 <span class="anchor" id="line-3"></span><span class="anchor" id="line-4"></span><p class="line867"><em>This module is not distributed with the Nginx source. Installation instructions are <a href="#installation">below</a>.</em> <span class="anchor" id="line-5"></span><span class="anchor" id="line-6"></span><p class="line874">The upstream_hash module provides simple upstream load distribution by hashing a configurable variable (e.g., the request URI, incoming HTTP headers, or some combination). Example usage: <span class="anchor" id="line-7"></span><span class="anchor" id="line-8"></span><p class="line867"><span class="anchor" id="line-9"></span><pre>upstream backend {
143 <span class="anchor" id="line-10"></span> server server1;
144 <span class="anchor" id="line-11"></span> server server2;
145 <span class="anchor" id="line-12"></span> hash $request_uri;
146 <span class="anchor" id="line-13"></span>}
147 <span class="anchor" id="line-14"></span></pre><span class="anchor" id="line-15"></span><span class="anchor" id="line-16"></span><p class="line874">Here, Nginx will choose server1 or server2 by hashing the request URI ($request_uri). <span class="anchor" id="line-17"></span><span class="anchor" id="line-18"></span><p class="line867">
148 <h2 id="head-e447c504fe73e1912886e3cfd5b335eb8a90a5a0">Directives</h2>
149 <span class="anchor" id="line-19"></span><span class="anchor" id="line-20"></span><ul><li><p class="line891"><a href="#hash">hash</a> <span class="anchor" id="line-21"></span></li><li><p class="line891"><a href="#hash_again">hash_again</a> <span class="anchor" id="line-22"></span><span class="anchor" id="line-23"></span></li></ul><p class="line867"><span class="anchor" id="hash"></span> <span class="anchor" id="line-24"></span><span class="anchor" id="line-25"></span><p class="line867">
150 <h2 id="head-3a857993d71a23ea824e238814ca4583265bc97d">hash</h2>
151 <span class="anchor" id="line-26"></span><p class="line867"><strong>syntax</strong> <em>hash $variable</em> <span class="anchor" id="line-27"></span><span class="anchor" id="line-28"></span><p class="line867"><strong>context</strong> <em>upstream</em> <span class="anchor" id="line-29"></span><span class="anchor" id="line-30"></span><p class="line874">Enables upstream hashing of $variable. <span class="anchor" id="line-31"></span><span class="anchor" id="line-32"></span><p class="line874">When present, the "server" directives cannot take any arguments ("weight", "max_fails", etc.). <span class="anchor" id="line-33"></span><span class="anchor" id="line-34"></span><p class="line867"><span class="anchor" id="hash_again"></span> <span class="anchor" id="line-35"></span>
152 <h2 id="head-36e090dc2c1cb75051fdd971bed7a8c6e8ce3cac">hash_again</h2>
153 <span class="anchor" id="line-36"></span><p class="line867"><strong>syntax</strong> <em>hash_again number</em> <span class="anchor" id="line-37"></span><span class="anchor" id="line-38"></span><p class="line867"><strong>default</strong> <em>0</em> <span class="anchor" id="line-39"></span><span class="anchor" id="line-40"></span><p class="line867"><strong>context</strong> <em>upstream</em> <span class="anchor" id="line-41"></span><span class="anchor" id="line-42"></span><p class="line874">Number of times to rehash the value and choose a different server if the backend connection fails. Increase this number to provide high availability. <span class="anchor" id="line-43"></span><span class="anchor" id="line-44"></span><p class="line867"><span class="anchor" id="installation"></span> <span class="anchor" id="line-45"></span>
154 <h2 id="head-f853b6cf504ff6af886bbf45b2dc09a3031f03d9">Installation</h2>
155 <span class="anchor" id="line-46"></span><span class="anchor" id="line-47"></span><p class="line862">This module is not distributed with the Nginx source. You can download the request_hash module here: <a class="http" href="http://wiki.codemongers.com/NginxHttpUpstreamRequestHashModule?action=AttachFile&do=get&target=nginx_upstream_hash-0.3.tar.gz">nginx_upstream_hash-0.3.tar.gz</a> <span class="anchor" id="line-48"></span><span class="anchor" id="line-49"></span><p class="line874">After extracting, you will need to patch the latest Nginx source (0.7.11 as of this writing). Run patch like this: <span class="anchor" id="line-50"></span><span class="anchor" id="line-51"></span><p class="line867"><span class="anchor" id="line-52"></span><pre> cd nginx-0.7.11
156 <span class="anchor" id="line-53"></span> patch -p0 < /path/to/upstream/hash/directory/nginx.patch
157 <span class="anchor" id="line-54"></span></pre><span class="anchor" id="line-55"></span><span class="anchor" id="line-56"></span><p class="line874">Then add the following option to your Nginx ./configure command: <span class="anchor" id="line-57"></span><span class="anchor" id="line-58"></span><p class="line867"><span class="anchor" id="line-59"></span><pre> --add-module=path/to/upstream/hash/directory
158 <span class="anchor" id="line-60"></span></pre><span class="anchor" id="line-61"></span><span class="anchor" id="line-62"></span><p class="line874">Then "make" and "make install" as usual. <span class="anchor" id="line-63"></span><span class="anchor" id="line-64"></span><p class="line867"><span class="anchor" id="hash-algorithm"></span> <span class="anchor" id="line-65"></span>
159 <h2 id="head-3c1201d51559ba07821752cd31e80902ed33cc95">The hash algorithm</h2>
160 <span class="anchor" id="line-66"></span><span class="anchor" id="line-67"></span><p class="line874">As of 0.3, the hash algorithm and the failover algorithm use a CRC-32 computation compatible with PECL Memcache. <span class="anchor" id="line-68"></span><span class="anchor" id="line-69"></span><p class="line867">
161 <h2 id="head-1468300db9cf366d94eec4f28e55a85a3d500e58">Changes</h2>
162 <span class="anchor" id="line-70"></span><span class="anchor" id="line-71"></span><ul><li style="list-style-type:none">* 0.3: Feature: PECL Memcache compatibility. Change: Removed "hash_method" directive. <span class="anchor" id="line-72"></span><span class="anchor" id="line-73"></span></li></ul><p class="line867">
163 <h2 id="head-5ff00a181108bf241a00b91bf8b7b9344eb005b5">Bugs</h2>
164 <span class="anchor" id="line-74"></span><span class="anchor" id="line-75"></span><p class="line862">Send bug reports to <a class="http" href="http://emiller.info">Evan Miller</a>. <span class="anchor" id="line-76"></span><span class="anchor" id="bottom"></span></div><div id="pagebottom"></div>
165 <p id="pageinfo" class="info" lang="en" dir="ltr">NginxHttpUpstreamRequestHashModule (last edited 2008-08-25 02:18:43 by <span title="Emiller @ 127.0.0.25[127.0.0.25]"><a href="/Emiller" title="Emiller @ 127.0.0.25[127.0.0.25]">Emiller</a></span>)</p>
167 <div id="pagebottom"></div>