Apr 212012
Article Apache

(Leer este artículo en español)

In an Apache web server installation in Linux, by default accesses are recorded in a file named access.log in the directory /var/log/apache2.

In the same way, errors are recorded in a file named ‘error.log’ under the same directory.

The problem is that these files keep growing, and this makes difficult the management and analysis of the information in them.

To fix this issue, we can configure the web server to create a new file every day.

The apache config file for our virtual server www.openalfa.com is located in the path ‘/etc/apache2/conf/sites_enabled/001-openalfa’.
Inside this file, in the <VirtualHost> section for this server, we add the directives:

As you can see, we make use of the pipe (“|”) character to redirect to the ‘rotatelogs’ utility the logs of accesses and errors .

The first argument of rotatelogs is the name of the destination file. It uses the parameters %Y, %m, etc. to include the date and time of creation as part of the filename.

The second argument (the number 86400) is the number of second in one day (86400 = 24 * 60 * 60).

Once the configuration file has been edited, we only need to restart the web service to force  the apache server to read the new configuration:

 Posted by at 2:33 pm

 Leave a Reply