同一域名路径根据不同header头分发到不同节点,以此来做灰度发布。 主要配置 通过 http_newversion 判断版本,转发至不同upstream。
server {
listen 80;
server_name test.bthlt.com;
underscores_in_headers on;
access_log /data/log/elk/test.bthlt.com.access.log weimob_json;
error_log /data/log/nginx/test.bthlt.com.error.log;
location / {
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X_CUSTOM_HEADER $http_host;
if ($http_newversion = '1'){
proxy_pass http://hl_v1_node;
}
if ($http_newversion = '2'){
proxy_pass http://hl_v2_node;
}
}
}
upstream hl_v1_node {
server 10.1.1.1:8080 id=102 weight=10;
keepalive 100;
check interval=3000 rise=2 fall=5 timeout=1000 type=tcp;
}
upstream hl_v2_node {
server 10.1.1.2:8080 id=102 weight=10;
keepalive 100;
check interval=3000 rise=2 fall=5 timeout=1000 type=tcp;
}
curl -H "newversion:2" http://test.bthlt.com
curl -H "newversion:1" http://test.bthlt.com