<div dir="ltr"><br class="gmail-Apple-interchange-newline"><table cellpadding="0" class="gmail-cf gmail-gJ" style="font-size:12.8px"><tbody><tr class="gmail-acZ"><td class="gmail-gF gmail-gK" style="width:492px"><table cellpadding="0" class="gmail-cf gmail-ix" style="width:492px"><tbody><tr><td><h3 class="gmail-iw"><span name="Reinis Rozitis" class="gmail-gD" style="font-size:12.8px">Reinis Rozitis said:</span></h3><div><span name="Reinis Rozitis" class="gmail-gD" style="font-size:12.8px"><span style="font-size:12.8px">Yes, you can use different hash mechanisms/keys (for example specific cookies etc):</span><br style="font-size:12.8px"><a href="https://nginx.org/en/docs/stream/ngx_stream_upstream_module.html#hash" rel="noreferrer" target="_blank" style="font-size:12.8px">https://nginx.org/en/docs/stream/ngx_stream_upstream_module.html#hash</a><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">There are also some third-party sticky cookie modules.</span><br></span></div><div><br></div><div>Took a look at the link, but I have no idea what that would look like in my upstream stanza. Can you provide an example of what that would look like if I had 3 different backend servers and wanted to ensure that my hash was based on a cookie, or based on just a hash that provided a different backend server per session?</div><div><br></div><div><span name="Reinis Rozitis" class="gmail-gD" style="font-size:12.8px"><br></span></div><div><span name="Reinis Rozitis" class="gmail-gD" style="font-size:12.8px">So in theory I could also just run a daily script to weight the servers differently or change the server order to manipulate how the hash is calculated? Has that ever been done with success?</span></div></td></tr></tbody></table></td></tr></tbody></table></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 27, 2016 at 3:44 PM, Reinis Rozitis <span dir="ltr"><<a href="mailto:r@roze.lv" target="_blank">r@roze.lv</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
My understanding is that the ip_hash directive is responsible for session persistence. My questions are:<br>
1) How long does it last? For example, if I connect and my ip hash tells nginx to connect to backend3, will my source IP be forever tied to backend 3?<br>
</blockquote>
<br></span>
If your IP doesn't change and all the servers are up, you will most likely always land on the same backend server.<br>
<a href="http://nginx.org/en/docs/http/ngx_http_upstream_module.html#ip_hash" rel="noreferrer" target="_blank">http://nginx.org/en/docs/http/ngx_http_upstream_module.html#ip_hash</a><span class=""><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
2) Is there another way to acheive session persistence other than ip hash and other than purchasing plus edition?<br>
</blockquote>
<br></span>
Yes, you can use different hash mechanisms/keys (for example specific cookies etc):<br>
<a href="https://nginx.org/en/docs/stream/ngx_stream_upstream_module.html#hash" rel="noreferrer" target="_blank">https://nginx.org/en/docs/stream/ngx_stream_upstream_module.html#hash</a><br>
<br>
There are also some third-party sticky cookie modules.<br>
<br>
<br>
I personally preffer to use centralised cache storage (memcache/redis etc) so it doesn't matter on which server the user lands and they can be used in roundrobin fashion.<span class=""><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
3) Is there an ip hash "cache" or something I can clean out periodically to force the source IP to get a new hash and therefore a chance to connect to a different server?<br>
</blockquote>
<br></span>
The standard nginx hash mechanisms don't have any inbuilt "cache". In case of ip_hash you can change the upstream server order (though it will swap arround all the users not only particular remote addr).<br>
<br>
rr <br>
_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org" target="_blank">nginx@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx" rel="noreferrer" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br>
</blockquote></div><br></div>