Apache
  Home arrow Apache arrow Logging in Apache
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
APACHE

Logging in Apache
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 20
    2005-05-12


    Table of Contents:
  • Logging in Apache
  • Security Issues of Log Files
  • Reading the Log Files
  • Remote Logging
  • Logging on a Remote Host
  • Advantages and Disadvantages of Logging on a Remote Machine
  • A Powerful, Hybrid Design
  • Room for Improvement

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Logging in Apache
    ( Page 1 of 8 )

    Administrators need keep regular tabs on their Web servers to make they are running smoothly, so that their clients don't meet with any unpleasant surprises. Logging helps you to spot performance problems before they become an issue, and also assists in the detection of possible security concerns. This article will discuss configuring Apache for logging purposes, and will go into some detail about remote logging solutions. It is excerpted from Hardening Apache by Tony Mobily (Apress, 2004; ISBN: 1590593782).

    mobilyKEEPING AN EYE ON WEB SERVERS so that they run smoothly is an essential part of the administrator’s job, for both performance and reliability purposes. Sensible logging helps to detect performance problems well before they become apparent to users, and provides evidence of potential security problems.

    In this chapter I will first explain how to configure Apache for logging purposes, highlighting the most common problems. I will then introduce remote logging using syslogd, the standard logging server that comes with Unix. Finally, I will propose a remote logging solution, which will allow you to encrypt logging information and store it on a remote database using MySQL.

    Why Logging?

    Log files show you what your daemons are doing. From a security perspective, Apache’s log files are used for:

    • Logging requests made and pages served in order to identify “suspicious” requests.

    • Logging Apache’s extra information, such as errors and warnings. This information is very interesting, because an attack generally creates some abnormal entries.

    The importance of log files is often underestimated. Sometimes, even in important production servers, they are left there to grow and grow, until one day they make themselves noticed because they have filled up the file system.

    NOTE Log files should never be placed on file systems that don’t support adequate logging. Typically that means NFS, but it might also mean Samba, AFS, and others. You must either log to a remote application or to a local file system.

    Configuring Logging in Apache

    I will give an overview of how to configure log files in Apache. Remember that this is not a comprehensive explanation, and for more information you should look at Apache’s official documentation: http://httpd.apache.org/docs/logs.html.

    Normal (Classic) Configuration

    There are two types of log information in Apache: the access log (handled by the module mod_log_config) and the error log.

    The access log records every request sent to the web server. A typical configuration is:

    LogFormat "%h %l %u %t \"%r\" %<s %b" common
    CustomLog logs/access_log common

    NOTE A better term for access log would be activity log, because you can use the powerful Apache directives to potentially create log files that just log unique ids or user-agents. However, in this book I will use the more common term access log.

    Here, LogFormat sets a log format and assigns a name to it, common in this case. Then, Apache is instructed to log access information in the file logs/access_log, using the format defined in the previous line (common). To find out the exact meaning of each parameter, check Apache’s documentation. You will find out that Apache can log almost anything pertaining to a request, including the client’s address and the type of request itself. The log file format just described is the most common for HTTP requests (for example, IIS is capable of generating the same result), hence its name.

    Apache server’s error messages are logged separately, using a different file. In this case, there is no definite format for the messages, and these directives are defined:

    ErrorLog logs/error_log
    LogLevel warn

    The first directive, ErrorLog, instructs Apache to log all the errors in logs/ error_log. The second directive sets the minimum importance for a message to be logged (the “level” of the message). These levels are defined in Table 3-1.

    LOGLEVEL SIGNIFICANCE OF ERROR
    emerg System is unstable
    alert Immediate action required
    crit Critical error
    error Non-critical error
    warn Warning
    notice Normal but significant
    info Informational
    debug Debug level

    Table 3-1. Apache Error Levels

    Remember that if you decide to set the log level to crit, the messages for more important levels will be logged as well (in this case, alert and emerg).

    NOTE Notice level messages are always logged, regardless of the LogLevel setting.

    Delegating Logging to an External Program

    Sometimes, it is advisable to delegate all the logging to specifically developed parsing engines or archiving utilities. When Apache is started, it runs the logging program and sends all the logging messages to it. This solution is valid in many situations. For example:

    • When you don’t want to stop and restart your Apache server to compress your logs.

    • When you have many virtual hosts. If you use a different log file for each virtual host, Apache will need to open two file descriptors for every virtual domain, wasting some of the kernel’s and processes’ resources.

    • When you want to centralize your logging into one single host. The program specified in the configuration could send the log lines elsewhere instead of storing them locally, or for increased reliability, it could do both.
    • When you want to create a special log filter that watches every log request looking for possible security problems.

    There are some disadvantages to using an external program. For example, if the program is too complex, it might consume too much CPU time and memory. In addition, if the external program has a small memory leak, it might eventually chew up all the system’s memory. Finally, if the logging program blocks, there is a chance of causing a denial of service on the server.

    To delegate logging to an external program ( piped logging), you can use the following syntax:

    CustomLog "|/usr/local/apache2/bin/rotatelogs
    /var/log/access_log 86400" common

    The command /usr/local/apache2/bin/rotatelogs /var/log/access_log 86400 is run by apache at startup time.

    In this case, the program rotatelogs will be fed the log lines by Apache, and will write them on /var/log/access_log. Remember that you can use the same syntax for Apache’s error log using the directive ErrorLog. For more information about how CustomLog and ErrorLog work, refer to Apache’s official documentation.



     
     
    >>> More Apache Articles          >>> More By Apress Publishing
     

       

    APACHE ARTICLES

    - Creating a VAMP (Vista, Apache, MySQL, PHP) ...
    - Putting Apache in Jail
    - Containing Intrusions in Apache
    - Server Limits for Apache Security
    - Setting Permissions in Apache
    - Installing Apache
    - Apache Installation and Configuration
    - Apache Tapestry and Custom Components: DateI...
    - Tapestry and AJAX: Autocompleter and InlineE...
    - PropertySelection and IPropertySelectionMode...
    - The DatePicker and Shell Components of Apach...
    - Apache Tapestry: ASO and More Components
    - Apache Tapestry and DirectLink, IoC and DI
    - Making a CelebrityCollector with Apache Tape...
    - Apache Tapestry and Listener Methods, Condit...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek