HAProxy系列文章：http://www.cnblogs.com/f-ck-need-u/p/7576137.html

haproxy提供了3种实现会话保持的方式：

• (1).源地址hash;
• (3).会话粘性表stick-table;

backend dynamic_servers

cookie <name> [ rewrite | insert | prefix ] [ indirect ] [ nocache ]
[ postonly ] [ preserve ] [ httponly ] [ secure ]
[ domain <domain> ]* [ maxidle <idle> ] [ maxlife <life> ]

<h1>response from webapp 192.168.100.61</h1>
<?php
session_start();
echo "Server IP: "."<font color=red>".$_SERVER['SERVER_ADDR']."</font>"."<br>"; echo "Server Name: "."<font color=red>".$_SERVER['SERVER_NAME']."</font>"."<br>";
echo "SESSIONNAME: "."<font color=red>".session_name()."</font>"."<br>";
echo "SESSIONID: "."<font color=red>".session_id()."</font>"."<br>";
?>

insert    This keyword indicates that the persistence cookie will have to
be inserted by haproxy in server responses if the client did not

already have a cookie that would have permitted it to access this
server. When used without the "preserve" option, if the server
emits a cookie with the same name, it will be remove before
processing.  For this reason, this mode can be used to upgrade
existing configurations running in the "rewrite" mode. The cookie
will only be a session cookie and will not be stored on the
client's disk. By default, unless the "indirect" option is added,
the server will see the cookies emitted by the client. Due to
caching effects, it is generally wise to add the "nocache" or
"postonly" keywords (see below). The "insert" keyword is not
compatible with "rewrite" and "prefix".

5. 由于缓存的影响，建议加上"nocache"或"postonly"选项。

backend dynamic_group

backend dynamic_group

'$status$body_bytes_sent "$http_referer" ' '"$http_user_agent" "\$http_x_forwarded_for"';

PHPSESSID=47d0ina2m14gg67ovdf1d972d1; app_cook=app_server1 192.168.100.59

PHPSESSID=bge3bh6sksu2ie91lsp8ep9oi2 192.168.100.59

prefix    This keyword indicates that instead of relying on a dedicated
cookie for the persistence, an existing one will be completed.
This may be needed in some specific environments where the client
does not support more than one single cookie and the application
already needs it. In this case, whenever the server sets a cookie
named <name>, it will be prefixed with the server's identifier
and a delimiter. The prefix will be removed from all client
requests so that the server still finds the cookie it emitted.
Since all requests and responses are subject to being modified,
this mode doesn't work with tunnel mode. The "prefix" keyword is
not compatible with "rewrite" and "insert". Note: it is highly
recommended not to use "indirect" with "prefix", otherwise server

backend dynamic_group

PHPSESSID=oses71hjr64dl6lputpkmdpg12 192.168.100.59 - -

rewrite   This keyword indicates that the cookie will be provided by the
server and that haproxy will have to modify its value to set the
server's identifier in it. This mode is handy when the management
of complex combinations of "Set-cookie" and "Cache-control"
headers is left to the application. The application can then
decide whether or not it is appropriate to emit a persistence
cookie. Since all responses should be monitored, this mode
doesn't work in HTTP tunnel mode. Unless the application
behaviour is very complex and/or broken, it is advised not to
incompatible with "insert" and "prefix".

backend dynamic_group

backend dynamic_group

backend dynamic_group
acl  url_dynamic   path_end  -i .php
ignore-persist if  url_dynamic