openresty+lua取客户端ip和userage
版权声明:
本文为博主原创文章,转载请声明原文链接...谢谢。o_0。
更新时间:
2020-12-16 12:57:52
温馨提示:
学无止境,技术类文章有它的时效性,请留意文章更新时间,如发现内容有误请留言指出,防止别人"踩坑",我会及时更新文章
--Get the client IP function get_client_ip() CLIENT_IP = ngx.req.get_headers()["X_real_ip"] if CLIENT_IP == nil then CLIENT_IP = ngx.req.get_headers()["X_Forwarded_For"] end if CLIENT_IP == nil then CLIENT_IP = ngx.var.remote_addr end if CLIENT_IP == nil then CLIENT_IP = "unknown" end return CLIENT_IP end --Get the client user agent function get_user_agent() USER_AGENT = ngx.var.http_user_agent if USER_AGENT == nil then USER_AGENT = "unknown" end return USER_AGENT end