nginx+lua控制转发资源
https://segmentfault.com/a/1190000018641801
upstream aaa{
server 47.105.104.145:10086 weight=1;
}
upstream bbb{
server 47.105.104.145:5000 weight=1;
}
server {
listen 80;
server_name localhost;
set $target 'aaa';
location /lua_test {
rewrite_by_lua_file /opt/lua/test.lua;
proxy_pass http://$target/;
}
}
local targetName = "aaa";
function setTarget()
-- 通过cookie转发
if (ngx.var.http_cookie == "123")
then
ngx.var.target = "bbb";
else
ngx.var.target = targetName;
end
end
function exceptionHandle(err)
ngx.log(ngx.ERR, err);
end
--添加异常处理
xpcall(setTarget, exceptionHandle);
|
请发表评论