杰网资源 Design By www.escxy.com

安装 memcached

yum install -y memcached
#启动memcached服务,端口11211,以nobody身份启动,-d后台模式运行
memcached -p11211 -u nobody -d
#将自己的IP设为灰度测试的IP
telnet 127.0.0.1 11211
set 119.32.216.122 0 0 1
1
quit

安装 memcached for lua

wget https://github.com/openresty/lua-resty-memcached/archive/v0.11.tar.gz
tar -zxvf v0.11.tar.gz
mkdir -p /usr/local/share/lua/5.1
cp -r lua-resty-memcached-0.11/lib/resty /usr/local/share/lua/5.1

创建 test.lua 文件

clientIP=ngx.req.get_headers()["X-Real-IP"]
if clientIP == nil then
  clientIP=ngx.req.get_headers()["x_forwarded_for"]
end
if clientIP == nil then
  clientIP=ngx.var.remote_addr
end
  local memcached=require "resty.memcached"
  local memc,err=memcached:new()
  if not memc then
    ngx.say("failed to instantiate memc:",err)
    return
  end
  local ok,err =memc:connect("127.0.0.1",11211)
  if not ok then
    ngx.say("failed to connect:",err)
    return
  end
  local res,flags,err =memc:get(clientIP)
  --ngx.say("value key: ",res,clientIP)
  if err then
    ngx.say("failed to get clientIP",err)
    return
  end
  if res == "1" then
    ngx.exec("@server_test")
    return
  end
  ngx.exec("@server_product")

nginx配置

  server {
    listen 8867;
    server_name www.siguoya.name;
    root /usr/local/nginx/1.12.1/html;
    location / {
      content_by_lua_file /etc/nginx/test.lua;
    }
    location /hello {
      default_type text/plain;
      content_by_lua 'ngx.say("hello lua")';
    }
    location /ua {
      default_type text/plain;
      content_by_lua '
        clientIP=ngx.req.get_headers()["USER-AGENT"]
        ngx.say("IP:",clientIP)
        ';
    }
    location @server_product {
      default_type text/plain;
      return 200 'product';
    }
    location @server_test {
      default_type text/plain;
      return 200 'test';
    }
  }

由于我们将 119.32.216.122 这个IP添加进了memcached中,因此访问 http://www.siguoya.name:8867/ 的时候,看到的内容就是 test

而开启全局代理之后,发现看到的内容就是 product,这样就实现了针对部分用户进行灰度测试的效果

标签:
Nginx与Lua灰度发布,Nginx,灰度发布

杰网资源 Design By www.escxy.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
杰网资源 Design By www.escxy.com

P70系列延期,华为新旗舰将在下月发布

3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。

而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?

根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。