灰度發佈策略:基於用戶標識,基於IP等
灰度發佈實現方式:
nginx+lua根據來訪者IP地址區分
nginx根據cookie分流
nginx根據權重分配
nginx基於用戶標識灰度發佈
upstream G1 {
server 127.0.0.1:8001;
}
upstream G2 {
server 127.0.0.1:8002;
}
server {
listen 80;
server_name localhost;
set $group G1;//設置變量group爲G1
if ($http_cookie ~* "version_id=new"){
set $group G2;
}
localhost / {
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;
}
}
nginx服務器監聽80,需要根據cookie轉發,查詢的cookie的鍵爲‘version_id’,(該鍵有開發在後臺寫cookie的時候寫入特定標識字段),如果該cookie的值爲new則轉發到B,其他則轉發到A