Apache Log Format for Web Servers Behind Load Balancer

If you are using a load balancer to balance the load to two or more web servers, usually only the IP address of the load balancer will be logged in the web logs instead of the visitor’s IP address.

To log visitor’s IP address, just create a custom log format with a new name , e.g. “lb_log” and used it in all the virtual host configured in Apache. Please always backup your original httpd.conf before you make any changes.

 
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
LogFormat “%{X-Forwarded-For}i %l %u %t \”%r\” %>s %b \”%{Referer}i\” \”%{User-Agent}i\”” lg_log
#….
# START_HOST example.com
<virtualhost *:80>
    ServerName example.com
    DocumentRoot “/var/www/example.com/html”
    <directory “/var/www/example.com/html”>
        Options Includes FollowSymLinks  
        AllowOverride All
        Order allow,deny
        Allow from all
    </directory>
    CustomLog /var/www/logs/example.com/access_log lb_log
    ErrorLog /var/www/logs/example.com/error_log
</virtualhost>
# END_HOST example.com

Before you make any changes to httpd.conf please go through Apache log module .

 

Reference:
http://www.imthi.com/blog/linux/apache-log-format-for-amazon-ec2-with-elastic-load-balancer.php

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s