GithubHelp home page GithubHelp logo

ngx_lua_waf_cf's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

ngx_lua_waf_cf's Issues

用户使用代理或者使用CDN,获取的ip是不是就不对了呀?

demo

-- 获取客户端IP
function getClientIp()
local headers = ngx.req.get_headers()
local clientIp = nil
-- 仅获取真实IP cloudflare:CF-Connecting-IP
-- 取消直接获取CF-Connecting-IP,当多层代理时获取的是假IP
-- clientIp = headers["CF-Connecting-IP"]
if type(headers["X-Forwarded-For"]) == "table" then
clientIp = headers["X-Forwarded-For"][1]
else
clientIp = headers["X-Forwarded-For"]
end

if clientIp == nil then
    clientIp = headers["X-Real-IP"]
end

if clientIp == nil then
    clientIp = ngx.var.remote_addr
end

if preg_match(clientIp,",") then
    local pos  = string.find(clientIp, ",", 1)
    clientIp = string.sub(clientIp,1,pos-1)
end

return clientIp

end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.