首先,作为loadblance的nginx需要添加下面的配置:
X-Real-IP和X-Forwarded-For可以2选1,也可以都打开。
然后:
1.如果backend是apache时:apache需要添加模块rpaf
http://stderr.net/apache/rpaf/
可以用于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 forward
RPAFproxy_ips 127.0.0.1 10.0.0.1
# which ips are forwarding requests to us
RPAFsethostname On
# let rpaf update vhost settings
# allows to have the same hostnames as in the "real"
# configuration for the forwarding Apache
RPAFheader X-Forwarded-For
# Allows you to change which header mod_rpaf looks
# for when trying to find the ip the that is forwarding
# our requests
# if DSO load module first: LoadModule rpaf_module libexec/apache2/mod_rpaf-2.0.so RPAFenable On RPAFsethostname On RPAFproxy_ips 192.168.1.23 (nginx loadblance server) RPAFheader X-Forwarded-For
2.如果是nginx做为backend的话:
作为backend的nginx在编译时需要添加模块
--with-http_realip_module
并修改nginx.conf:
context为: http, server, location