在使用openresty的时候发现如果在openresty上面再加上一成代理,则lua获取不到真实的IP地址,最开始使用:ngx.var.remote_addr 获取IP
最后解决方案:
1:在代理服务器上配置
location /services {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://192.168.110.98/services;
}
2:lua获取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"