Monday, May 4, 2015

Testing X-Forwarded-For on HAProxy.

1) Configure your front-end server in HAProxy and enable X-Forwarded-For

frontend virtual_cluster_server
   mode http
   bind 10.156.209.110:80 transparent
   option httplog clf
   log global
   option forwardfor

2) Configure your httpd.conf in Apache Server to log the "X-forwarded-host" header. Ensure you have lines like this:

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{X-Forwarded-For}i\" \"%{User-Agent}i\"" combined

customLog logs/access_log combined

Note:
1) For sake of simplicity, I have changed the "combined" format for access_log.
2) You could do something similar for individual virtual hosts, inside the definitions.

3) Access your haproxy URL and you'd see a line logged like below for your client-IP

172.16.10.2 - - [04/May/2015:06:37:42 -0400] "GET /api/service.php HTTP/1.1" 200 6 "-" "10.112.202.162" "curl/7.37.1"

You can see that it has displayed the value of X-Forwarded-For in the logs which happens to be my client IP.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home