zoukankan      html  css  js  c++  java
  • nginx做白名单以及灰度流量控制

    首先是nginx.conf

    user root root;
    worker_processes 4;
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
        include gated_launch.conf;
        server {
            listen       80;
            server_name  localhost;
            location / {
                add_header gated_launch $gated_launch;
                add_header white_list $white_list;
                root   html;
            }
        }
    }

    gated_launch.conf

    split_clients "${arg_uid}" $gated_launch {
      50% true;
      50% false;
    }
    
    map $arg_uid $white_list {
      20 true;
      50 true;
      60 true;
      5678 true;
      default false;
    }

    调用方访问以下接口,即可知道该请求是否在白名单以及灰度名单中。

    127.0.0.1:80/?uid=1

    注意端口号后面的/是必须的,不然拿不到header。

    response只包含header,如下:

    HTTP/1.1 200 OK

    Server: nginx/1.9.3

    Date: Thu, 12 Nov 2015 03:25:56 GMT

    Content-Type: text/html

    Content-Length: 0

    Last-Modified: Thu, 12 Nov 2015 02:11:36 GMT

    Connection: keep-alive

    ETag: "5643f558-0"

    gated_launch: true

    white_list: false

    Accept-Ranges: bytes

    gated_launch 表示是否在灰度名单。

    white_list 表示是否在白名单。

  • 相关阅读:
    分页查询
    web 开发中 405报错
    html 中input标签的name属性
    怎么样利用debug
    bzoj 1314: River过河 优先队列
    bzoj 4004: [JLOI2015]装备购买 拟阵 && 高消
    bzoj 1133: [POI2009]Kon dp
    bzoj 4127: Abs 树链剖分
    bzoj 2406: 矩阵 上下界网络流判定
    再写FFT模板
  • 原文地址:https://www.cnblogs.com/longzhaoyu/p/4958724.html
Copyright © 2011-2022 走看看