首先:
做为loadblance的nginx要添加下面的配置:
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和X-Forwarded-For可以2选1,也可以都打开:
然后:
1.如果backend是apache时: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:
192.168.2.1;(该ip为nginx loadblance ip)
X-Real-IP;
context为: http, server, location
更多,查看:
阅读(4639) | 评论(0) | 转发(0) |