好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > Nginx與Lua灰度發布的實現

Nginx與Lua灰度發布的實現

熱門標簽:廈門防封電銷電話卡 云南電商智能外呼系統哪家好 地圖標注能更改嗎 濰坊寒亭400電話辦理多少錢 四川保險智能外呼系統 地圖標注員有發展前景嗎 宜賓銷售外呼系統軟件 高德地圖標注公司需要錢 外呼系統全國

安裝 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與Lua灰度發布內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持腳本之家!

標簽:德州 巴彥淖爾 紅河 回訪 湛江 廊坊 廣安 滁州

巨人網絡通訊聲明:本文標題《Nginx與Lua灰度發布的實現》,本文關鍵詞  Nginx,與,Lua,灰度,發布,的,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Nginx與Lua灰度發布的實現》相關的同類信息!
  • 本頁收集關于Nginx與Lua灰度發布的實現的相關信息資訊供網民參考!
  • 推薦文章