From 8d718e31a0cbb7bf6b9078cb8d786b53b7e1c8c2 Mon Sep 17 00:00:00 2001 From: zzm <86479242@qq.com> Date: Sat, 15 May 2021 16:35:27 +0800 Subject: [PATCH] Update init.lua MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ip获取需要考虑是否为转发IP或是否为本机 --- init.lua | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/init.lua b/init.lua index 2eb5966..2a11798 100644 --- a/init.lua +++ b/init.lua @@ -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")