Chapter 7. Logging
Finding bad links
Most browsers also include a query header Referer: which contains the URL of the
page that contain the link the user queried to bring them here. This can be particularly
useful to find remote pages that have bad links onto your site.
CustomLog "%{Referer}i %U %>s" referer_log
Figure 7-14. Logging referers
Those pages which have bad links pointing into your site will generate status
code 404 and can be tracked down.
Log rotation
It is one thing to create logs; it is quite another to cope with them. A log file grows
without bound unless action is taken and this can cause problems.
Problems with growing log files
• Larger files are harder to manipulate.
• File systems run out of space.
• The information you log may constitute personal data.
A solution to this generic problem of log file growth is log rotation. This involves the
regular (nightly or weekly, typically) moving of an existing log file to some other file
name and starting fresh with an empty log file. After a period the old log files get
thrown away.
Because this is a general issue, Red Hat Linux provides a general solution that can be
applied to any set of log files, not just the web server’s. There is an Apache-specific
solution (which is provided by the rotatelogs command) but we will use Red Hat
Linux’s generic solution, provided in the logrotate package.
Once each night the logrotate program reads in its configuration files telling it which
logs to rotate and how to do it. One of these instructions tells it to rotate any file in
/var/log/httpd whose name ends with log.
# rotate log files weekly
weekly
# keep 4 weeks worth of backlogs
rotate 4
# create new (empty) log files after rotating old ones
create
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d
Figure 7-15. /etc/logrotate.conf: The main log rotation file
The main configuration file sets up the defaults and then reads in a directory of in-
structions for specific sets of log files from the /etc/logrotate.d directory.
/etc/logrotate.conf: commands
weekly
Each file should be rotated weekly. The log rotation job runs nightly, though, so
this can be changed to daily for a specific log file if desired.
57
Kommentare zu diesen Handbüchern