nginx使用set_real_ip_from获取用户的真实IP地址
前言
因公司Nginx现在方案也只是主备模式,利用keeplive+nginx方式实现主备故障切换。但这模式可能造成资源浪费,于是打算利用硬件lvs实现双活,但是验证过程获取不到用户真实ip地址。于是通过查看Nginx官方说明进行配置验证:https://nginx.org/en/docs/http/ngx_http_realip_module.html
过程
查看nginx支持模块
查看nginx是否存在with-http_realip_module
模块,默认情况下不会构建此模块,应重新编译configuration
添加 --with-http_realip_module
参数启用它。
修改nginx.conf
参数
在 http 模块
添加如下参数:
主要这种方式只能支持在7层HTTP协议生效,如果是4层TCP协议暂时无解。
测试验证
参考
1.https://www.cnblogs.com/chenjw-note/p/10785181.html
2.https://nginx.org/en/docs/http/ngx_http_realip_module.html