<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>How to select a server based on client ip ?</title>
        <description> Hi,

If we have 5 servers within a back-end, how can we specify some request to certain server based on client ip?

For example:

backend
	server s01
	server s02
	server s03
	server s04
	server s05

How can we make all requests comes from 217.192.7.* goes to server s01 ? 

Thanks.</description>
        <link>http://www.serverphorums.com/read.php?10,462619,462619#msg-462619</link>
        <lastBuildDate>Sun, 19 May 2013 10:04:00 +0200</lastBuildDate>
        <generator>Phorum 5.2.18</generator>
        <item>
            <guid>http://www.serverphorums.com/read.php?10,462619,464084#msg-464084</guid>
            <title>Re: How to select a server based on client ip ?</title>
            <link>http://www.serverphorums.com/read.php?10,462619,464084#msg-464084</link>
            <description><![CDATA[ Hi Cyril,<br />
<br />
On Sat, Mar 17, 2012 at 12:46:03AM +0100, Cyril Bonté wrote:<br />
&gt; Hi,<br />
&gt; <br />
&gt; Le 15/03/2012 08:39, wsq003 a écrit :<br />
&gt; &gt;Thanks, Carlo. It works.<br />
&gt; &gt;But can it be simpler? such as:<br />
&gt; &gt;frontend http<br />
&gt; &gt;bind :80<br />
&gt; &gt;mode http<br />
&gt; &gt;default_backend pool<br />
&gt; &gt;<br />
&gt; &gt;backend pool<br />
&gt; &gt;server s01 2.3.4.1:80<br />
&gt; &gt;server s02 2.3.4.2:80<br />
&gt; &gt;server s03 2.3.4.3:80<br />
&gt; &gt;use_server s01 if { src 217.192.7.0/24 }<br />
&gt; <br />
&gt; If you're in http mode, you may use some tricks to emulate this (Note <br />
&gt; that I've never tested it in production).<br />
&gt; <br />
&gt; First, use &quot;cookie&quot; keyword without any actions (no prefix, insert or <br />
&gt; rewrite option) :<br />
&gt; <br />
&gt;   cookie LB<br />
&gt; <br />
&gt; Add cookie values on each server :<br />
&gt; <br />
&gt;   server s01 2.3.4.1:80 cookie s01<br />
&gt;   server s02 2.3.4.2:80 cookie s02<br />
&gt;   server s03 2.3.4.3:80 cookie s03<br />
&gt; <br />
&gt; Then enumerate the acls you want to reach a specific server :<br />
&gt; <br />
&gt;   acl s01 src 217.192.7.0/24<br />
&gt;   acl s02 ...<br />
&gt; <br />
&gt; <br />
&gt; Ask haproxy to add a fake cookie depending on the acl matching :<br />
&gt; <br />
&gt;   reqadd Cookie:\ LB=s01 if s01<br />
&gt; <br />
&gt; And maybe you want to force the persistence for such conditions :<br />
&gt; <br />
&gt;   force-persist if s01 || s02 ...<br />
&gt; <br />
&gt; To sum up, this gives :<br />
&gt; <br />
&gt; backend pool<br />
&gt;   mode http<br />
&gt;   # use option httpclose or option http-server-close<br />
&gt;   ...<br />
&gt;   cookie LB<br />
&gt; <br />
&gt;   server s01 2.3.4.1:80 cookie s01<br />
&gt;   server s02 2.3.4.2:80 cookie s02<br />
&gt;   server s03 2.3.4.3:80 cookie s03<br />
&gt; <br />
&gt;   acl s01 src 217.192.7.0/24<br />
&gt;   acl s02 ...<br />
&gt; <br />
&gt;   reqadd Cookie:\ LB=s01 if s01<br />
&gt; <br />
&gt;   force-persist if s01 || s02 ...<br />
&gt; <br />
&gt; Consider this experimental unless someone confirms he already used this <br />
&gt; in production ;-)<br />
<br />
Yes it works because req* rules are processed before cookie inspection.<br />
I've used something about similar in some setups, which consisted in<br />
renaming a header &quot;x-something: YZ&quot; to &quot;cookie: SRV=YZ&quot; to get the same<br />
behaviour.<br />
<br />
I think I should update the diagram which details all the processing steps<br />
because a number of additions were made and not updated there.<br />
<br />
Regards,<br />
Willy]]></description>
            <dc:creator>Willy Tarreau</dc:creator>
            <category>HAProxy</category>
            <pubDate>Sat, 17 Mar 2012 09:00:01 +0100</pubDate>
        </item>
        <item>
            <guid>http://www.serverphorums.com/read.php?10,462619,463939#msg-463939</guid>
            <title>Re: How to select a server based on client ip ?</title>
            <link>http://www.serverphorums.com/read.php?10,462619,463939#msg-463939</link>
            <description><![CDATA[ Hi,<br />
<br />
Le 15/03/2012 08:39, wsq003 a écrit :<br />
&gt; Thanks, Carlo. It works.<br />
&gt; But can it be simpler? such as:<br />
&gt; frontend http<br />
&gt; bind :80<br />
&gt; mode http<br />
&gt; default_backend pool<br />
&gt;<br />
&gt; backend pool<br />
&gt; server s01 2.3.4.1:80<br />
&gt; server s02 2.3.4.2:80<br />
&gt; server s03 2.3.4.3:80<br />
&gt; use_server s01 if { src 217.192.7.0/24 }<br />
<br />
If you're in http mode, you may use some tricks to emulate this (Note <br />
that I've never tested it in production).<br />
<br />
First, use &quot;cookie&quot; keyword without any actions (no prefix, insert or <br />
rewrite option) :<br />
<br />
   cookie LB<br />
<br />
Add cookie values on each server :<br />
<br />
   server s01 2.3.4.1:80 cookie s01<br />
   server s02 2.3.4.2:80 cookie s02<br />
   server s03 2.3.4.3:80 cookie s03<br />
<br />
Then enumerate the acls you want to reach a specific server :<br />
<br />
   acl s01 src 217.192.7.0/24<br />
   acl s02 ...<br />
<br />
<br />
Ask haproxy to add a fake cookie depending on the acl matching :<br />
<br />
   reqadd Cookie:\ LB=s01 if s01<br />
<br />
And maybe you want to force the persistence for such conditions :<br />
<br />
   force-persist if s01 || s02 ...<br />
<br />
To sum up, this gives :<br />
<br />
backend pool<br />
   mode http<br />
   # use option httpclose or option http-server-close<br />
   ...<br />
   cookie LB<br />
<br />
   server s01 2.3.4.1:80 cookie s01<br />
   server s02 2.3.4.2:80 cookie s02<br />
   server s03 2.3.4.3:80 cookie s03<br />
<br />
   acl s01 src 217.192.7.0/24<br />
   acl s02 ...<br />
<br />
   reqadd Cookie:\ LB=s01 if s01<br />
<br />
   force-persist if s01 || s02 ...<br />
<br />
Consider this experimental unless someone confirms he already used this <br />
in production ;-)<br />
<br />
-- <br />
Cyril Bonté]]></description>
            <dc:creator>Cyril Bonté</dc:creator>
            <category>HAProxy</category>
            <pubDate>Sat, 17 Mar 2012 00:50:02 +0100</pubDate>
        </item>
        <item>
            <guid>http://www.serverphorums.com/read.php?10,462619,463929#msg-463929</guid>
            <title>Re: Re: How to select a server based on client ip ?</title>
            <link>http://www.serverphorums.com/read.php?10,462619,463929#msg-463929</link>
            <description><![CDATA[ Hey wsq003.  I don't believe it can be simpler because of the nature of<br />
creating ACLs in HAProxy.  However, you could make this much more elegant<br />
by a) programmatically creating the ACLs and/or b) using something like<br />
haproxy_join ( <a href="https://github.com/joewilliams/haproxy_join" target="_blank"  rel="nofollow">https://github.com/joewilliams/haproxy_join</a> ) or Puppet's<br />
concat module ( <a href="https://github.com/ripienaar/puppet-concat" target="_blank"  rel="nofollow">https://github.com/ripienaar/puppet-concat</a> ) to break up<br />
the configuration files into a more readable format.<br />
<br />
Even a simpler format that constantly changes would be hairy and needs<br />
automation to not be hairy, right? :)<br />
<br />
On Thu, Mar 15, 2012 at 12:39 AM, wsq003 &lt;wsq003@sina.com&gt; wrote:<br />
<br />
&gt; **<br />
&gt;<br />
&gt; Thanks, Carlo. It works.<br />
&gt;<br />
&gt; But can it be simpler? such as:<br />
&gt;<br />
&gt;  frontend http<br />
&gt;  bind :80<br />
&gt;  mode http<br />
&gt;  default_backend pool<br />
&gt;<br />
&gt; backend pool<br />
&gt;  server s01 2.3.4.1:80 <a href="http://2.3.4.1/" target="_blank"  rel="nofollow">http://2.3.4.1/</a><br />
&gt;  server s02 2.3.4.2:80 <a href="http://2.3.4.2/" target="_blank"  rel="nofollow">http://2.3.4.2/</a><br />
&gt;  server s03 2.3.4.3:80 <a href="http://2.3.4.3/" target="_blank"  rel="nofollow">http://2.3.4.3/</a><br />
&gt;   use_server s01 if { src 217.192.7.0/24 }<br />
&gt;<br />
&gt; We have many servers for different developers, the rules may be complex<br />
&gt; and changing.<br />
&gt; It is not elegant to define hundreds of backend.<br />
&gt;<br />
&gt;<br />
&gt;  *From:* Carlo Flores &lt;lo@js.la&gt;<br />
&gt; *Date:* 2012-03-15 14:45<br />
&gt; *To:* wsq003 &lt;wsq003@sina.com&gt;<br />
&gt; *CC:* haproxy &lt;haproxy@formilux.org&gt;<br />
&gt; *Subject:* Re: How to select a server based on client ip ?<br />
&gt;  See the src entry under section 7.5.1 of the HAProxy docs.  There's<br />
&gt; actually many examples of this acl you'll find throughout the doc.  You'd<br />
&gt; use something like this:<br />
&gt;<br />
&gt;  frontend http<br />
&gt;   bind :80<br />
&gt;   mode http<br />
&gt;   acl always_s01 src 217.192.7.0/24<br />
&gt;   use_backend s01 if always_s01<br />
&gt;   default_backend pool<br />
&gt;<br />
&gt; backend s01<br />
&gt;   server s01 2.3.4.1:80<br />
&gt;<br />
&gt; backend pool<br />
&gt;   server s01 2.3.4.1:80<br />
&gt;   server s02 2.3.4.2:80<br />
&gt;   server s03 2.3.4.3:80<br />
&gt;<br />
&gt;<br />
&gt; On Wed, Mar 14, 2012 at 11:09 PM, wsq003 &lt;wsq003@sina.com&gt; wrote:<br />
&gt;<br />
&gt;&gt; Hi,<br />
&gt;&gt;<br />
&gt;&gt; If we have 5 servers within a back-end, how can we specify some request<br />
&gt;&gt; to certain server based on client ip?<br />
&gt;&gt;<br />
&gt;&gt; For example:<br />
&gt;&gt;<br />
&gt;&gt; backend<br />
&gt;&gt;        server s01<br />
&gt;&gt;        server s02<br />
&gt;&gt;        server s03<br />
&gt;&gt;        server s04<br />
&gt;&gt;        server s05<br />
&gt;&gt;<br />
&gt;&gt; How can we make all requests comes from 217.192.7.* goes to server s01 ?<br />
&gt;&gt;<br />
&gt;&gt; Thanks.<br />
&gt;&gt;<br />
&gt;<br />
&gt;]]></description>
            <dc:creator>Carlo Flores</dc:creator>
            <category>HAProxy</category>
            <pubDate>Sat, 17 Mar 2012 00:20:01 +0100</pubDate>
        </item>
        <item>
            <guid>http://www.serverphorums.com/read.php?10,462619,462646#msg-462646</guid>
            <title>Re: Re: How to select a server based on client ip ?</title>
            <link>http://www.serverphorums.com/read.php?10,462619,462646#msg-462646</link>
            <description><![CDATA[ Thanks, Carlo. It works.<br />
<br />
But can it be simpler? such as:<br />
<br />
frontend http<br />
 bind :80<br />
 mode http<br />
 default_backend pool <br />
<br />
<br />
backend pool<br />
 server s01 2.3.4.1:80<br />
 server s02 2.3.4.2:80<br />
 server s03 2.3.4.3:80<br />
 use_server s01 if { src 217.192.7.0/24 }<br />
<br />
We have many servers for different developers, the rules may be complex and changing.<br />
It is not elegant to define hundreds of backend.<br />
<br />
<br />
From: Carlo Flores<br />
Date: 2012-03-15 14:45<br />
To: wsq003<br />
CC: haproxy<br />
Subject: Re: How to select a server based on client ip ?<br />
See the src entry under section 7.5.1 of the HAProxy docs.  There's actually many examples of this acl you'll find throughout the doc.  You'd use something like this:<br />
<br />
<br />
frontend http<br />
  bind :80<br />
  mode http<br />
  acl always_s01 src 217.192.7.0/24<br />
  use_backend s01 if always_s01<br />
  default_backend pool <br />
<br />
<br />
backend s01<br />
  server s01 2.3.4.1:80 <br />
<br />
<br />
backend pool<br />
  server s01 2.3.4.1:80<br />
  server s02 2.3.4.2:80<br />
  server s03 2.3.4.3:80<br />
<br />
<br />
<br />
<br />
On Wed, Mar 14, 2012 at 11:09 PM, wsq003 &lt;wsq003@sina.com&gt; wrote:<br />
<br />
Hi,<br />
<br />
If we have 5 servers within a back-end, how can we specify some request to certain server based on client ip?<br />
<br />
For example:<br />
<br />
backend<br />
       server s01<br />
       server s02<br />
       server s03<br />
       server s04<br />
       server s05<br />
<br />
How can we make all requests comes from 217.192.7.* goes to server s01 ?<br />
<br />
Thanks.]]></description>
            <dc:creator>wsq003</dc:creator>
            <category>HAProxy</category>
            <pubDate>Thu, 15 Mar 2012 08:50:01 +0100</pubDate>
        </item>
        <item>
            <guid>http://www.serverphorums.com/read.php?10,462619,462628#msg-462628</guid>
            <title>Re: How to select a server based on client ip ?</title>
            <link>http://www.serverphorums.com/read.php?10,462619,462628#msg-462628</link>
            <description><![CDATA[ See the src entry under section 7.5.1 of the HAProxy docs.  There's<br />
actually many examples of this acl you'll find throughout the doc.  You'd<br />
use something like this:<br />
<br />
frontend http<br />
  bind :80<br />
  mode http<br />
  acl always_s01 src 217.192.7.0/24<br />
  use_backend s01 if always_s01<br />
  default_backend pool<br />
<br />
backend s01<br />
  server s01 2.3.4.1:80<br />
<br />
backend pool<br />
  server s01 2.3.4.1:80<br />
  server s02 2.3.4.2:80<br />
  server s03 2.3.4.3:80<br />
<br />
<br />
On Wed, Mar 14, 2012 at 11:09 PM, wsq003 &lt;wsq003@sina.com&gt; wrote:<br />
<br />
&gt; Hi,<br />
&gt;<br />
&gt; If we have 5 servers within a back-end, how can we specify some request to<br />
&gt; certain server based on client ip?<br />
&gt;<br />
&gt; For example:<br />
&gt;<br />
&gt; backend<br />
&gt;        server s01<br />
&gt;        server s02<br />
&gt;        server s03<br />
&gt;        server s04<br />
&gt;        server s05<br />
&gt;<br />
&gt; How can we make all requests comes from 217.192.7.* goes to server s01 ?<br />
&gt;<br />
&gt; Thanks.<br />
&gt;]]></description>
            <dc:creator>Carlo Flores</dc:creator>
            <category>HAProxy</category>
            <pubDate>Thu, 15 Mar 2012 07:50:01 +0100</pubDate>
        </item>
        <item>
            <guid>http://www.serverphorums.com/read.php?10,462619,462619#msg-462619</guid>
            <title>How to select a server based on client ip ?</title>
            <link>http://www.serverphorums.com/read.php?10,462619,462619#msg-462619</link>
            <description><![CDATA[ Hi,<br />
<br />
If we have 5 servers within a back-end, how can we specify some request to certain server based on client ip?<br />
<br />
For example:<br />
<br />
backend<br />
	server s01<br />
	server s02<br />
	server s03<br />
	server s04<br />
	server s05<br />
<br />
How can we make all requests comes from 217.192.7.* goes to server s01 ? <br />
<br />
Thanks.]]></description>
            <dc:creator>wsq003</dc:creator>
            <category>HAProxy</category>
            <pubDate>Thu, 15 Mar 2012 07:20:01 +0100</pubDate>
        </item>
    </channel>
</rss>
