Update init.lua

ip获取需要考虑是否为转发IP或是否为本机
pull/160/head
zzm 2021-05-15 16:35:27 +08:00 committed by GitHub
parent 314a2f62ec
commit 8d718e31a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 5 deletions

View File

@ -15,11 +15,9 @@ attacklog = optionIsOn(attacklog)
CCDeny = optionIsOn(CCDeny)
Redirect=optionIsOn(Redirect)
function getClientIp()
IP = ngx.var.remote_addr
if IP == nil then
IP = "unknown"
end
return IP
local headers=ngx.req.get_headers()
local ip=headers["X-REAL-IP"] or headers["X_FORWARDED_FOR"] or ngx.var.remote_addr or "0.0.0.0"
return ip
end
function write(logfile,msg)
local fd = io.open(logfile,"ab")