First: Nginx as loadblance to add the following configuration:
Proxy_set_header Host $host; Proxy_set_header X-real-ip $remote _addr; Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for; |
X-real-ip and X-forwarded-for can be 2 1 or open: more, view http://blog.chinaunix.net/u/32831/showart_1908231.html Then: 1. If backend is Apache: Apache needs to add a module RPAF
http://stderr.net/apache/rpaf/
Can be used with Apache 2.2 Compile and install for 1.3:apxs-i-a-c MOD_RPAF.C Compile and install for 2.0:apxs-i-c-n mod_rpaf-2. 0.so mod_rpaf-2.0.c or simply try:make Configuration directives:rpafenable on# Enable Reverse proxy add forwardrpafproxy_i PS 127.0.0.1 10.0.0.1# which IPS is forwarding requests to Usrpafsethostname on# let RPAF update vhost settings # allows To has the same hostnames as in the ' real ' # Configuration for the forwarding Apacherpafheader x-forwarded-for# allows To change which header MOD_RPAF looks# for when trying to find the IP the that's forwarding# our requests
# if DSO load module First:loadmodule rpaf_module libexec/apache2/mod_rpaf-2.0.so rpafenable on Rpafsethostname on RPAFPR Oxy_ips 192.168.1.23 (nginx loadblance server) Rpafheader x-forwarded-for |
2. If it is nginx as backend words: Backend as the Nginx in the compilation need to add modules
--with-http_realip_module
and modify the nginx.conf:
Set_real_ip_from 192.168. 2. 1; (the IP is nginx loadblance IP)real_ip_header x-real-ip;
the context is: http, server, location
More, view:
Http://wiki.nginx.org/NginxHttpRealIpModule
About Nginx doing load balancing when backend server takes real IP