From 03bb26dd908591fe01325f9ca8ff177d8552a5d9 Mon Sep 17 00:00:00 2001
From: Richard Bowen When using a large number of Virtual Hosts, Apache may run
out of available file descriptors (sometimes called file
- handles if each Virtual Host specifies different log
+ handles) if each Virtual Host specifies different log
files. The total number of file descriptors used by Apache is
one for each distinct error log file, one for every other log
file directive, plus 10-20 for internal use. Unix operating
@@ -29,11 +29,11 @@
this may not work if:
-
setrlimit()
+ system call.setrlimit(RLIMIT_NOFILE)
call does not
+ function on your system (such as Solaris 2.3)
<VirtualHost>
+ sections, but only log to the main log files. (See Splitting up your log files, below, for more
+ information on doing this.)
If you want to log multiple virtual hosts to the same log file, you +may want to split up the log files afterwards in order to run +statistical analysis of the various virtual hosts. This can be +accomplished in the following manner.
+ +First, you will need to add the virtual host information to the log
+entries. This can be done using the LogFormat
+directive, and the %v
variable. Add this to the beginning
+of your log format string:
+ +
+ LogFormat "%v %h %l %u %t \"%r\" %>s %b" vhost
+ CustomLog logs/multiple_vhost_log vhost +
This will create a log file in the common log format, but with the +canonical virtual host (whatever appears in the +../mod/core.html#servername">ServerName directive) prepended to +each line. (See Custom Log Formats for +more about customizing your log files.)
+ +When you wish to split your log file into its component parts (one +file per virtual host) you can use a program like the following to +accomplish this:
+ ++ +
+#!/usr/bin/perl +# Filename: split_log +# Usage: split_log multiple_vhost_log +# Creates one log file per virtual host + +use strict; +my $file = $ARGV[0]; # Name of the log file +my %fh; # File handles + +# Read the log file, one line at a time +open LOG, $file; +foreach my $line (<LOG>) { + $line =~ s/^(.*?) //; + + # Do we already have a file handle for this vhost? + unless ($fh{$1}) { + my $handle; + open ($handle, '>' , $1 . '_split'); + $fh{$1} = $handle; + } + + # Write out the log entry + select ($fh{$1}); + print $line; +} +close LOG; + +# Close all the open file handles +foreach my $h ( keys %fh ) { + close $h; +} +
This program, when run with the name of your vhost log file, will
+generate one file for each virtual host that appears in your log file.
+Each file will be called hostname_split
.