Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Implementation of grayscale release of Nginx and Lua

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Install memcached

yum install -y memcached#Start memcached service, port 11211, start as nobody, -d background mode run memcached -p11211 -u nobody -d#Set IP to greyscale IPtelnet 127.0.0.1 11211set 119.32.216.122 0 0 11quit

Install 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

Create test.lua file

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 configuration

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'; } }

Since we added the IP www.example.com to memcached, when visiting http://www.siguoya.name:8867/, what we see is test. 119.32.216.122

After the global proxy is turned on, it is found that the content you see is product, which achieves the effect of gray scale testing for some users.

This article on the implementation of Nginx and Lua gray published article on this, more related Nginx and Lua gray published content please search for previous articles or continue to browse the following related articles hope that you will support a lot later!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report