Apache X-Forwarded-For

Wenn der Apache hinter einem Proxy / Loadbalancer läuft, sorgt diese Config dafür das die Client IP im X-Forwarded-For Header auch im Logfile steht.
Dazu muss man lediglich eine zusätzliche Config Datei für den Apache anlegt werden.

Apache X-Forwarded-For

[stextbox id=“bash“]nano /etc/apache2/conf-available/X-Forwarded-For.conf[/stextbox]

# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
# If you are behind a reverse proxy, you might want to change %h into %{X-Forwarded-For}i

# # Orginal
#LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
#LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
#LogFormat "%h %l %u %t \"%r\" %>s %O" common
#LogFormat "%{Referer}i -> %U" referer
#LogFormat "%{User-agent}i" agent

# # Angepasstes Logfile
SetEnvIf REMOTE_ADDR "(.+)" CLIENTIP=$1
SetEnvIf X-Forwarded-For "^(.+)" CLIENTIP=$1

LogFormat "%{CLIENTIP}e - %v:%p %l %u %t -Micro %D -Sek %T \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%{CLIENTIP}e - %{Host}i %l %u %t -Micro %D -Sek %T \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%{CLIENTIP}e - %{Host}i %l %u %t -Micro %D -Sek %T \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

 

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

*