Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ops
/
yoho-ansible-roles
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
chunhua.zhang
5 years ago
Commit
3e62007c620d2711d3f7d7856e5d954d202e5404
1 parent
836e92ee
add
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
9 deletions
roles/openresty/files/java-nginx-config/nginx/conf/local.access.conf
roles/openresty/files/java-nginx-config/nginx/conf/lua/limit_local_access.lua
roles/openresty/files/java-nginx-config/nginx/conf/local.access.conf
View file @
3e62007
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
...
...
roles/openresty/files/java-nginx-config/nginx/conf/lua/limit_local_access.lua
View file @
3e62007
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
...
...
Please
register
or
login
to post a comment