Apache 在代理后显示正确的用户IP
apache日志中默认有%h来指定来访客户端你的ip地址,但是如果客户端使用了代理上网则%h获得的ip地址会不准。可以设定 X-Forwarded-For 参数来获取客户端真实的ip地址
对于使用了反向代理的客户端,跟踪真实的ip地址
- %{X-Forwarded-For}i
- LogFormat "%{X-Forwarder-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" linuxanyproxy
- LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
- SetEnvIf X-Forwarder-For "^.*\..*\..*\..*" is-forwarder
- CustomLog logs/access_log combined env=!is-forwarder
- CustomLog logs/access_log linuxanyproxy env=is-forwarder