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
How to view files in a docker image 1. If it is a...
Table of contents What is Rract? background React...
Table of contents Drag and drop implementation Dr...
Implementation of regular backup of Mysql databas...
Original link: https://vien.tech/article/157 Pref...
Directly to the configuration file server { liste...
Table of contents cluster Cluster Details Events ...
Table of contents 1. Single database backup 2. Co...
The virtual machine used is CentOS 8.4, which sim...
Table of contents Creating OAuth Apps Get the cod...
Problem description: After executing docker run -...
This article example shares the specific code of ...
Without further ado, here is a demo picture. The ...
Pessimistic Lock Pessimistic lock, considers the ...
How to delete the container created in Docker 1. ...