带有X_Forwarded和HAProxy的Nginx HttpGeoIPModule

是否有可能使Nginx HttpGeoIPModule使用通过HAProxy发送的X_Forwarded IP? 它目前只是使用不正确的服务器IP,但不确定如何让Nginx使用X_Forwarded IP。

有任何想法吗?

您是否尝试过使用RealIPModule并将X-Real-IP设置为X-Forwarded-For

您必须在编译期间传递–with-http_realip_module来构build模块,因为它不是默认生成的。

http://wiki.nginx.org/HttpRealIpModule

Sameer的回答是正确的。

您需要使用–with-http_realip_module选项来configuration和编译Nginx。

然后在Nginxconfiguration中设置以下选项:

set_real_ip_from 1.2.3.4;

real_ip_header X-Forwarded-For;

其中1.2.3.4是HAProxy的IP地址

在HAProxy中,您需要以下选项:

option httpclose

option forwardfor

我发现这个网站很有帮助: http : //www.somerorbay.com/vps-and-dedicated/nginx-behind-haproxy-x-forwarded-for-getting-real-client-ip

另一个select是在透明模式下运行HA代理,然后所有IP将正确显示。 通常需要一些小小的IP桌面“捣碎”来使其工作,但非常值得。