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
c7045e6fbd4ba7fab1c15f9c71f13cfa763201fa
1 parent
82d076e1
add
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
5 deletions
roles/openresty/files/java-nginx-config/nginx/conf/lua/limit_local_access.lua
roles/openresty/files/java-nginx-config/nginx/conf/lua/limit_local_access.lua
View file @
c7045e6
...
...
@@ -23,15 +23,34 @@ local local_cidr = {
"123.206.73.107"
}
local
function
get_ip
()
local
realIp
=
nil
local
xForwardFor
=
ngx
.
var
.
http_x_forwarded_for
;
if
xForwardFor
then
local
ips
=
{}
string.gsub
(
xForwardFor
,
'[^,]+'
,
function
(
w
)
table.insert
(
ips
,
w
)
end
)
realIp
=
ips
[
#
ips
]
end
-- if not exist, then setup remote_addr
if
realIp
==
nil
then
realIp
=
ngx
.
var
.
remote_addr
;
end
if
realIp
then
realIp
=
string.gsub
(
realIp
,
"%s"
,
""
)
end
return
realIp
;
end
-- check if ip is local
-- depends on $real_ip which setup by setup.lua
function
M
:
check_local_access
()
local
ip
=
ngx
.
var
.
real_ip
if
(
ip
==
nil
or
ip
==
''
)
then
return
false
end
local
ip
=
get_ip
()
local
is_local_ip
=
false
for
i
=
1
,
#
local_cidr
do
...
...
Please
register
or
login
to post a comment