<div dir="ltr">Thank you for your reply.<div><br></div><div>What I want to solve is that backup servers can be selected when all the primary servers are unavailable.</div><div><br></div><div>Now I use error_page to solve it, but it's not convenient in the case of multi-servers-locations.</div><div>Especially some locations have already config error_page directive.</div><div><br></div><div>upstream backends {</div><div>    hash $uri consistent;</div><div>    server 10.0.0.1;</div><div>    server 10.0.0.2;</div><div>}</div><div><br></div><div><div>upstream backup {</div><div>    server 10.0.0.3;</div><div>}</div></div><div><br></div><div><font color="#000000" face="STHeiti" size="3">server {</font></div><div>     ...</div><div>     location / {</div><div>        error_page  502 504 = @fallback;</div><div>        proxy_pass  <a href="http://backends">http://backends</a>;</div><div>     }</div><div><br></div><div>     location @fallback {</div><div>        proxy_pass  <a href="http://backup">http://backup</a>;</div><div>     }</div><div>}</div><div><br></div><div>But if hash support backup, it would be handier, such as following.<br></div><div><br></div><div><div>upstream backends {</div><div>    hash $uri consistent;</div><div>    server 10.0.0.1;</div><div>    server 10.0.0.2;</div><div>    server 10.0.0.3  backup; # Unfortunately it's now allowed.</div><div>}</div><div><br></div><div><font color="#000000" face="STHeiti" size="3">server {</font></div><div>     ...</div><div>     location / {</div><div>        proxy_pass  <a href="http://backends">http://backends</a>;</div><div>     }</div><div>}</div></div><div><br></div><div>Anyway.</div><div><br></div><div>1. Can you share the reason for "backup" option is not allowed combined with the hash module?</div><div>2. Is there any problem if I add the flag <font color="#000000">'<span style="font-size:12.8px">NGX_HTTP_UPSTREAM_BACKUP'  in the hash module?</span></font></div><div><font color="#000000"><span style="font-size:12.8px">    I know it's not an ideal design.</span></font></div><div><font color="#000000"><span style="font-size:12.8px"><br></span></font></div><div><font color="#000000"><span style="font-size:12.8px">Thanks again.<br></span></font><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 8, 2017 at 9:11 PM, Ruslan Ermilov <span dir="ltr"><<a href="mailto:ru@nginx.com" target="_blank">ru@nginx.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Mon, Nov 06, 2017 at 09:35:14PM +0800, 洪志道 wrote:<br>
>    Hi!<br>
>    We know that consistent hash upstream improve its selection in the latest<br>
>    version.<br>
><br>
>  -        if (hp->tries >= points->number) {<br>
>  -            pc->name = hp->rrp.peers->name;<br>
>  +        if (hp->tries > 20) {<br>
>               ngx_http_upstream_rr_peers_<wbr>unlock(hp->rrp.peers);<br>
>  -            return NGX_BUSY;<br>
>  +            return hp->get_rr_peer(pc, &hp->rrp);<br>
><br>
>  Does it mean that "backup" option is allowed in the module?<br>
<br>
</span>It just means that if, after 20 tries, we weren't able to select<br>
a peer using the hash algorithm, then we'll continue a selection<br>
process using the round-robin algorithm.  This is also consistent<br>
with the ip_hash module.<br>
<span class=""><br>
>                     |NGX_HTTP_UPSTREAM_MAX_CONNS<br>
>                     |NGX_HTTP_UPSTREAM_MAX_FAILS<br>
>                     |NGX_HTTP_UPSTREAM_FAIL_<wbr>TIMEOUT<br>
>  +                  |NGX_HTTP_UPSTREAM_BACKUP<br>
>                     |NGX_HTTP_UPSTREAM_DOWN;<br>
<br>
</span>We do not support backup servers with ip_hash and hash balancers,<br>
though there's currently a bypass that allows to have backup<br>
servers in configurations with hash balancers.  But these backup<br>
servers will be used only when falling back to round-robin, which<br>
is unlikely.<br>
<span class=""><br>
>  I wonder how to archive the effect of "backup" in hash like round robin,<br>
>  even if we don't want to use error_page.<br>
<br>
</span>I'm not sure what did you mean here.<br>
______________________________<wbr>_________________<br>
nginx-devel mailing list<br>
<a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" rel="noreferrer" target="_blank">http://mailman.nginx.org/<wbr>mailman/listinfo/nginx-devel</a></blockquote></div><br></div>