前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >teg nginx根据header分流

teg nginx根据header分流

作者头像
葫芦
发布2019-09-18 10:26:07
2.3K0
发布2019-09-18 10:26:07
举报
文章被收录于专栏:葫芦葫芦

nginx根据header分流

不同header头分发到不同节点

同一域名路径根据不同header头分发到不同节点,以此来做灰度发布。 主要配置 通过 http_newversion 判断版本,转发至不同upstream。

test.bthlt.com.conf

代码语言:javascript
复制
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

代码语言:javascript
复制
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

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019/09/17 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • nginx根据header分流
    • 不同header头分发到不同节点
      • test.bthlt.com.conf
      • upstream
    • 测试
    相关产品与服务
    命令行工具
    腾讯云命令行工具 TCCLI 是管理腾讯云资源的统一工具。使用腾讯云命令行工具,您可以快速调用腾讯云 API 来管理您的腾讯云资源。此外,您还可以基于腾讯云的命令行工具来做自动化和脚本处理,以更多样的方式进行组合和重用。
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档