Authored by chunhua.zhang

add

set $real_ip "";
set_by_lua_file $real_ip conf/setup.lua;
access_by_lua_block {
access_by_lua '
local local_limit = require "limit_local_access"
local status, is_local = pcall(local_limit:check_local_access)
if not status then
ngx.log(ngx.ERR, "call method [check_local_access] failed.", errMsg)
else
if not is_local_ip then
if not is_local then
ngx.exit(403)
end
end
}
';
 
\ No newline at end of file
... ...
local moduleName = ...
local M = {}
_G[moduleName] = M
local modname= ...
local M={}
_G[modname]=M
package.loaded[modname]=M
-- author: chunhua.zhang
-- only allow request from local ip and nat ip
... ... @@ -25,7 +25,8 @@ local local_cidr = {
-- check if ip is local
-- depends on $real_ip which setup by setup.lua
function M.check_local_access()
function M:check_local_access()
local ip=string.gsub(ngx.var.remote_addr,"%s","")
local is_local_ip = false
... ... @@ -38,4 +39,6 @@ function M.check_local_access()
end
return is_local_ip
end
\ No newline at end of file
end
... ...