Install memcached yum install -y memcached #Start the memcached service, port 11211, start as nobody, -d background mode to run memcached -p11211 -u nobody -d #Set your own IP as the grayscale test IP telnet 127.0.0.1 11211 set 119.32.216.122 0 0 1 1 quit Install 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 Create test.lua file 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 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 119.32.216.122 to memcached, when we visit http://www.siguoya.name:8867/, we see the content test After turning on the global proxy, I found that the content I saw was the product, which achieved the effect of grayscale testing for some users. This is the end of this article about the implementation of grayscale release of Nginx and Lua. For more relevant content about grayscale release of Nginx and Lua, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Differences between ES6 inheritance and ES5 inheritance in js
>>: Detailed explanation of how to create an updateable view in MySQL
Table of contents Download tf-gpu Build your own ...
Suddenly, I needed to build a private service for...
Table of contents Preface 1.1 Function 1.2 How to...
Table of contents Introduction effect principle f...
Ubuntu 18.04, other versions of Ubuntu question: ...
Table of contents Master-slave replication mechan...
1) Scope of application: readonly:input[type="...
Table of contents Create a table View the databas...
Table of contents Primary key constraint Unique p...
Table of contents MutationObserver API Features I...
Click here to return to the 123WORDPRESS.COM HTML ...
Here are 10 HTML tags that are underused or misun...
Lock classification: From the granularity of data...
The use of Vue+ElementUI Tree is for your referen...
This article shares with you the graphic tutorial...