nginx用的是宝塔安装~~,自用mark一下nginx配置
location / {
access_by_lua '
local redis = require "resty.redis";
local red = redis:new();
red:set_timeout(200);
local ok, err = red:connect("127.0.0.1", 6379);
local allow_ips, err = red:hvals("task_map");
-- task_map 为存允许ip集合
if err then
return ngx.exit(ngx.HTTP_FORBIDDEN);
else
local allowEnter = false
for index, allow_ip in ipairs(allow_ips) do
if allow_ip == ngx.var.remote_addr then
allowEnter = true
break;
end
end
if allowEnter then
-- 允许通过
else
return ngx.exit(ngx.HTTP_FORBIDDEN);
end
end
';
}
网友评论