1. Add the following parameters to the haproxy.cfg.
Option Forwardfor #如果后端服务器需要获得客户端真实ip需要配置的参数, must be placed under the Listen module
2. If it is Apache, add the following parameter (i.e. modify)
Logformat "\"%{x-forwarded-for}i\ "%l%t \"%r\ "%>s%b \"%{referer}i\ "\"%{user-agent}i\ "" combined is mainly "\"%{ X-forwarded-for}i\ This parameter can record IP
Here we can write so conveniently cut logs Logformat "%{x-forwarded-for}i%l%t \"%r\ "%>s%b \"%{referer}i\ "\"%{user-agent}i\ "" Combined note space Class, can be copied directly
3. If the backend web is Nginx, add the following parameters
Set_real_ip_from IP, (this IP is filled with 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" '
============================================= (The following log path is also defined as main and Apache, which belongs to a log format)
Add $remote_addr or $http_x_forwarded_for parameters to the Log_format.
Haproxy forwarding real IP to the Web