基于cookies的nginx灰度发布
灰 度发布是指在黑与白之间,能够平滑过渡的一种发布方式。AB test就是一种灰度发布方式,让一部分用户继续用A,一部分用户开始用B,如果用户对B没有什么反对意见,那么逐步扩大范围,把所有用户都迁移到B上面 来。灰度发布可以保证整体系统的稳定,在初始灰度的时候就可以发现、调整问题,以保证其影响度。
灰度发布一般有三种方式 nginx+lua,nginx根据cookie分流,nginx 根据权重来分配
nginx+lua根据来访者ip地址区分,由于公司出口是一个ip地址,会出现访问网站要么都是老版,要么都是新版,采用这种方式并不适合
nginx 根据权重来分配,实现很简单,也可以尝试
nginx根据cookie分流,灰度发布基于用户才更合理
两台服务器分别定义为
tts_V6 192.168.3.81:5280
tts_V7 192.168.3.81:5380
默认服务器为:
default:192.168.3.81:5280
前端nginx服务器监听端口80,需要根据cookie转发,查询的cookie的键(key)为tts_version_id(该键由开发负责增加),如果该cookie值(value)为tts1则转发到tts_V6,为tts2则转发到tts_V7。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
upstream
tts_V6
{
server
192.168.3.81
:
5280
max_fails
=
1
fail_timeout
=
60
;
}
upstream
tts_V7
{
server
192.168.3.81
:
5380
max_fails
=
1
fail_timeout
=
60
;
}
upstream
default
{
server
192.168.3.81
:
5280
max_fails
=
1
fail_timeout
=
60
;
}
server
{
listen
80
;
server
_name
test
.
taotaosou
.
com
;
access
_log
logs
/
test
.
taotaosou
.
com
.
log
main
buffer
=
32k
;
#match cookie
set
$
group
"default"
;
if
(
$
http_cookie
~
*
"tts_version_id=tts1"
)
{
set
$
group
tts_V6
;
}
if
(
$
http_cookie
~
*
"tts_version_id=tts2"
)
{
set
$
group
tts_V7
;
}
location
/
{
proxy_pass
http
:
//$group;
proxy_set
_header
Host
$
host
;
proxy_set
_header
X
-
Real
-
IP
$
remote_addr
;
proxy_set
_header
X
-
Forwarded
-
For
$
proxy_add_x_forwarded_for
;
index
index
.
html
index
.
htm
;
}
}
|
转自:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=531464&id=4140473
收 藏
成长的对话版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!