如何解决nginx-lua白名单需求宁静的api
我在redis中有一个IP列入白名单,每个宁静的请求都需要检查ip
LUA代码
local redis = require "resty.redis"
local red = redis:new()
red:set_timeout(1000)
local ip = ngx.var.remote_addr
local redis_host = "192.168.1.2"
local port = 3767
local ok,err = red:connect(redis_host,port)
if not ok then
ngx.say("connect to redis error:",err)
return close_redis(red)
end
local key = "whitelist:"..ip
local res = red:get(key)
if res == ngx.null then
return ngx.ext(ngx.HTTP_FORBIDDEN);
else
return true;
end
nginx.conf
server {
listen 443;
location /v1/web/ {
default_type "text/plain";
access_by_lua_file /usr/local/nginx/conf/lua/test.lua;
}
}
当ip不在白名单中时,返回403是可以的,但是当ip在白名单中时,应继续请求宁静的api
我该如何更改我的conf文件
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。