Forum Moderators: phranque
Here is the problem. When a request comes in for a dynamic file (.php). The request is logged only on the back end server. Since the request is being proxied via the front end server, the log shows the front end server's IP address, and not the client's IP. This is a major problem for our log analysis tools (awstats currently), as we are losing data on all of those pages.
Can someone help me find a way to properly record these requests for dynamic pages to my logs, including the client that requested them, so that our log analysis tools show accurate data?
It would be best if I could just find a way to log all requests as if they weren't being redirected, to the front end server.
Here are the pertinent bits from my vhosts.conf:
RewriteEngine On
RewriteCond %{REQUEST_URI}!.*\.(ico¦jpg¦jpeg¦gif¦pdf¦png¦zip¦tgz¦gz¦bmp¦htm¦html)$
RewriteMap server rnd:/etc/apache2/conf/backend-servers.map
RewriteRule ^/(.*) [${server:web}.domain.com...] [P]
As an aside, it should be noted that you *could* use the LogFormat directive to construct a format which would log the request of the actual client's IP on the back-end hosts. LogFormat supports the logging of arbitrary headers via the %{HEADER}i option, and mod_proxy sets the 'X-Forwarded-For' header when making an outbound request; therefore, this:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\" %{X-Forwarded-For}i" combined
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined
Here, it can be captured by a rewrite condition such as this:
RewriteCond %{ENV:ORIG_IP} (.*) And - on the receiving end you can then use the same module to reset your front end server IP address back to the original one. It might take a bit of work to find the right formula, but it can be done.
There's a few examples (unrelated to this issue) here: [webmasterworld.com...] (posts #61,62) - as well as links to the relevant Apache docs.