Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ba0f3/8709b57e85c75103759f698d8471a1e3 to your computer and use it in GitHub Desktop.
Save ba0f3/8709b57e85c75103759f698d8471a1e3 to your computer and use it in GitHub Desktop.
Haproxy - Capture client IP when behind CloudFlare or not. Also keep x-forwarded-for in logs
frontend www-http
bind :80
bind *:443 ssl crt /etc/haproxy/certs no-sslv3
capture request header X-Forwarded-For len 50
acl is_cf req.hdr(cf-connecting-ip) -m found
http-request set-header X-Client-IP %[src] if !is_cf
http-request set-header X-Client-IP %[hdr(cf-connecting-ip)] if is_cf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment