Nginx与Lua灰度发布的实现
发表于:2025-02-06 作者:千家信息网编辑
千家信息网最后更新 2025年02月06日,安装 memcachedyum install -y memcached#启动memcached服务,端口11211,以nobody身份启动,-d后台模式运行memcached -p11211 -u
千家信息网最后更新 2025年02月06日Nginx与Lua灰度发布的实现
安装 memcached
yum install -y memcached#启动memcached服务,端口11211,以nobody身份启动,-d后台模式运行memcached -p11211 -u nobody -d#将自己的IP设为灰度测试的IPtelnet 127.0.0.1 11211set 119.32.216.122 0 0 11quit
安装 memcached for lua
wget https://github.com/openresty/lua-resty-memcached/archive/v0.11.tar.gztar -zxvf v0.11.tar.gzmkdir -p /usr/local/share/lua/5.1cp -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"]endif clientIP == nil then clientIP=ngx.var.remote_addrend 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灰度发布内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
灰度
内容
文章
就是
测试
全局
后台
效果
文件
时候
更多
模式
用户
端口
身份
部分
面的
代理
搜索
支持
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
软件开发公司机器设备
2022年emule服务器地址
赌博软件开发一个多少钱
洪洞云启网络技术有限公司
深圳嵌入式软件开发报价
云服务器1带宽够用吗
汽车网络安全事件
尚义网络安全培训会
数据库应用设想
数据库字符数据类型有哪些
湖州软件开发方向
上海安卓软件开发周期
微软服务器操作系统如何设置
easyrec连数据库
1.12.2最受欢迎的服务器
安全狗服务器设置教程
调整数据库表的字段长度
网络安全员会不会有隐私
微信小程序怎么读数据库
svn服务器 ssl
华为刀片服务器维修公司
sybase数据库使用权限
软件开发前的主要功能设计
ios互通服务器汇总一览
东莞网络安全和信息化委员会
led拼接屏用服务器主机怎么调
数据库中的控件
服务器 趋势
数据库如何添加本地缓存
衣服画的服务器