Skip to content

Instantly share code, notes, and snippets.

@AndisGrossteins
Last active October 11, 2019 01:54
Show Gist options
  • Save AndisGrossteins/68469346adbc379f3ad74138e3ab6f5b to your computer and use it in GitHub Desktop.
Save AndisGrossteins/68469346adbc379f3ad74138e3ab6f5b to your computer and use it in GitHub Desktop.
A hack to log real IP addresses on share Apache hosting behind CloudFlare (or other) reverse proxy
# Set environment variables from request headers and add them to User-Agent header
# it's not much but it works
# Requirements:
# 1 - mod_setenvif (http://httpd.apache.org/docs/current/mod/mod_setenvif.html)
# 2 - mod_headers (http://httpd.apache.org/docs/current/mod/mod_headers.html)
<IfModule mod_setenvif.c>
# Add envirinment variables from a request header
SetEnvIf CF-Connecting-IP "^(.+)$" CF_Connecting_IP=$1
</IfModule>
<IfModule mod_headers.c>
# This adds the variable only if it exists
RequestHeader append "User-Agent" "CFIP=%{CF_Connecting_IP}e" env=CF_Connecting_IP
RequestHeader append "User-Agent" "XFF=%{HTTP_X_FORWARDED_FOR}e" env=HTTP_X_FORWARDED_FOR
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment