HAproxy 让后端RS记录真实IP

#让RS记录客户端的真实IP

#1.先在haproxy.cfg中加入下面参数。

(1)

    defaults  

............

  option http-server-close

(2)listen www
...
option forwardfor 

          
#如果后端服务器需要获得客户端真实ip需要配置的参数,必须要放在listen模块下 

#2.如果是apache,则加入下面参数

LogFormat  “”%{X-Forwarded-For}i”%l %t "%r" %>s %b "%{Referer}i""%{User-Agent}i"" combined
主要是“”%{X-Forwarded-For}i 这个参数可以记录IP

#3.如果是后端RS是nginx则加入下面参数

set_real_ip_from ip;(这个ip填写的是proxy的ip)
 
real_ip_header X-Forwarded-For;

log_format main ‘$remote_addr – $remote_user [$time_local] “$request” ‘ 
                ‘$status $body_bytes_sent “$http_referer” ‘ 
                ‘”$http_user_agent” “$http_x_forwarded_for”‘
=============================================

原文地址:https://www.cnblogs.com/Crazy-Liu/p/11287752.html