骞没蕴 发表于 2019-1-1 12:36:15

Haproxy 让后端RS记录真实IP

  #让RS记录客户端的真实IP
  #1.先在haproxy.cfg中加入下面参数。
  
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”‘
=============================================
在log_format里添加$remote_addr或者$http_x_forwarded_for参数。  




页: [1]
查看完整版本: Haproxy 让后端RS记录真实IP