Recipe 3.14 Logging Server IP Addresses

Problem

You want to log the IP address of the server that responds to a request, possibly because you have virtual hosts with multiple addresses each.

Solution

Use the %A format effector in a LogFormat or CustomLog directive:

CustomLog logs/served-by.log "%{UNIQUE_ID}e %A"

Discussion

The %A effector signals the activity logging system to insert the local IP address that is, the address of the server into the log record at the specified point. This can be useful when your server handles multiple IP addresses. For example, you might have a configuration that includes elements such as the following:

Listen 10.0.0.42 Listen 192.168.19.243 Listen 263.41.0.80 <VirtualHost 192.168.19.243>     ServerName Private.Example.Com </VirtualHost> <VirtualHost 10.0.0.42 263.41.0.80>     ServerName Foo.Example.Com     ServerAlias Bar.Example.Com </VirtualHost>

This might be meaningful if you want internal users to access Foo.Example.Com using the 10.0.0.42 address rather than the one published to the rest of the network (such as to segregate internal from external traffic over the network cards). The second virtual host is going to receive requests aimed at both addresses even though it has only one ServerName; using the %A effector in your log format can help you determine how many hits on the site are coming in over each network interface.

See Also

  • The mod_log_config documentation



Apache Cookbook
Apache Cookbook: Solutions and Examples for Apache Administrators
ISBN: 0596529945
EAN: 2147483647
Year: 2006
Pages: 215

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net