Use lua scripts gray forwarding traffic on nginx

Reference material

idea + openresty + lua development environment to build

OpenResty Best Practices

Gray publish cookie-based diversion

Obtaining values ​​from the request

-- 从请求中获取请求头为 Sec-WebSocket-Protocol 的值
secWebSocketProtocol=ngx.req.get_headers()["Sec-WebSocket-Protocol"]

-- 从 cookie 中获取uid对应的值
uid=ngx.var.cookie_uid

-- 获取我们在 nginx 中定义的变量
-- set $lct "initialD";
location=ngx.var.lct

-- 从请求头中获取来源 ip
ip=headers["X-REAL-IP"] or headers["X_FORWARDED_FOR"] or ngx.var.remote_addr

Explanation

Guess you like

Origin www.cnblogs.com/daleyzou/p/luaWithNginx.html