Recipe 3.14 Logging Server IP Addresses


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.


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

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


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 Listen Listen <VirtualHost>     ServerName Private.Example.Com </VirtualHost> <VirtualHost>     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 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

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: