How to configure logging in Apache Web server
Read Time:1 Minute, 55 Second

How to configure logging in Apache Web server

0 0
0 0

In this guide let us see how to log any required particular logs in Apache web server.

To read about Apache related topic click on below links.

    1. How to install Apache Web Server in Red Hat Enterprise Linux 7 and Variants
    2. Understanding Apache Web Server logs

  • Is it possible to log a client IP Address which coming through the proxy?

No, we cant log clients IP which coming through Proxy.

  • Is it possible to log a client MAC Address in Apache logs?

In Apache, this is not possible.

  • Is it possible to logging cookies?

Yes, its possible by defining below directive in httpd configuration.

To log clients, cookies define directive as follows.

CustomLog logs/cookies_in.log "%{UNIQUE_ID}e %{Cookie}i"
CustomLog logs/cookies2_in.log "%{UNIQUE_ID}e %{Cookie2}i"

To log server to the client cookies

CustomLog logs/cookies_out.log "%{UNIQUE_ID}e %{Set-Cookie}o"
CustomLog logs/cookies2_out.log "%{UNIQUE_ID}e %{Set-Cookie2}o"
  • Is it possible to rotate logfiles in Apache Web Server?

Yes, its possible by defining customLog directive as follows.

Just we need to pipe the logs through rotate logs. By default, rotate logs will be available once we have done with installing httpd package.

CustomLog "| /usr/sbin/rotatelogs /var/log/httpd/access_log.%Y-%m-%d 86400" combined

86400 = 1 day

  • Log Hostnames Instead of IP Addresses

While we install Apache web server using httpd package we may notice httpd-tools will installed as its dependencies, it contains the tool logresolve we can locate it under /usr/bin/logresolve.

Logresolve will help to resolve the hostname from IP address. By defining below directive we can log and resolve the hostname from IP address under httpd configuration.

HostnameLookups On
CustomLog "| /usr/bin/logresolve -c >> /var/log/httpd/access_log.resolved" combined
  • To log the name of browser used by end user.

If we required knowing which browser is used by end users we need to append with below string in Custom log directive.

CustomLog /var/log/httpd/agent_log "%{User-agent}i"

In this chapter, we have seen about logging particular required things in Apache. In next chapter let us see how to define a virtual host in Apache Web server in various methods.

About Post Author

Babin Lonston

Overall 14+ Years of experience in the IT field, currently working as a Senior Linux administration with Virtualization & Cloud. Being numismatist for a long time.
0 0 %
0 0 %
0 0 %
0 0 %
0 0 %
0 0 %

Average Rating

5 Star
4 Star
3 Star
2 Star
1 Star

Leave a Reply

Your email address will not be published.

Previous post Understanding Apache Web Server logs
Next post Creating Luks Encrypted filesystem in Linux | 1 Easy guide

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

We promise not to spam you, and we don't usually send more than one email a week.

You have Successfully Subscribed!

Exit mobile version