﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-liuyf8688-文章分类-Nginx</title><link>http://www.blogjava.net/liuyf8688/category/54506.html</link><description /><language>zh-cn</language><lastBuildDate>Wed, 27 Aug 2014 08:18:38 GMT</lastBuildDate><pubDate>Wed, 27 Aug 2014 08:18:38 GMT</pubDate><ttl>60</ttl><item><title>Session persistence in Nginx</title><link>http://www.blogjava.net/liuyf8688/articles/417389.html</link><dc:creator>liuyf8688</dc:creator><author>liuyf8688</author><pubDate>Wed, 27 Aug 2014 02:16:00 GMT</pubDate><guid>http://www.blogjava.net/liuyf8688/articles/417389.html</guid><wfw:comment>http://www.blogjava.net/liuyf8688/comments/417389.html</wfw:comment><comments>http://www.blogjava.net/liuyf8688/articles/417389.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/liuyf8688/comments/commentRss/417389.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/liuyf8688/services/trackbacks/417389.html</trackback:ping><description><![CDATA[<center style="font-family: Georgia, serif; font-size: medium; line-height: normal; background-color: #ffffff;"><h4><br /></h4></center><p style="text-align: justify; font-family: Georgia, serif; font-size: medium; line-height: normal; background-color: #ffffff;">Please note that with round-robin or least-connected load balancing, each subsequent client&#8217;s request can be potentially distributed to a different server. There is no guarantee that the same client will be always directed to the same server.</p><p style="text-align: justify; font-family: Georgia, serif; font-size: medium; line-height: normal; background-color: #ffffff;">If there is the need to tie a client to a particular application server&nbsp;&#8212; in other words, make the client&#8217;s session &#8220;sticky&#8221; or &#8220;persistent&#8221; in terms of always trying to select a particular server&nbsp;&#8212; the ip-hash load balancing mechanism can be used.</p><p style="text-align: justify; font-family: Georgia, serif; font-size: medium; line-height: normal; background-color: #ffffff;">With ip-hash, the client&#8217;s IP address is used as a hashing key to determine what server in a server group should be selected for the client&#8217;s requests. This method ensures that the requests from the same client will always be directed to the same server except when this server is unavailable.</p><p style="text-align: justify; font-family: Georgia, serif; font-size: medium; line-height: normal; background-color: #ffffff;">To configure ip-hash load balancing, just add the&nbsp;<a href="http://nginx.org/en/docs/http/ngx_http_upstream_module.html#ip_hash">ip_hash</a>&nbsp;directive to the server (upstream) group configuration:</p><blockquote style="margin: 1em 0px 1em 1em; padding: 0.5em; border-left-width: 1px; border-left-color: #bbbbbb; color: #000000; font-family: Georgia, serif; font-size: medium; line-height: normal; background-color: #ffffff;"><pre style="padding: 0px; margin-top: 0px; margin-bottom: 0px;">upstream myapp1 {     <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ip_hash;     <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;server srv1.example.com;     <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;server srv2.example.com;     <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;server srv3.example.com; <br />}</pre></blockquote><img src ="http://www.blogjava.net/liuyf8688/aggbug/417389.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/liuyf8688/" target="_blank">liuyf8688</a> 2014-08-27 10:16 <a href="http://www.blogjava.net/liuyf8688/articles/417389.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>