fd-limits.xml revision 84ef01e0cc5691422370a55f218f43f425d99a9c
fb18194cd0e59b737cc179eb2354a2dcd16087d4trawick<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
fb18194cd0e59b737cc179eb2354a2dcd16087d4trawick<manualpage>
fb18194cd0e59b737cc179eb2354a2dcd16087d4trawick<parentdocument href="./">Virtual Hosts</parentdocument>
fb18194cd0e59b737cc179eb2354a2dcd16087d4trawick <p>When using a large number of Virtual Hosts, Apache may run
fb18194cd0e59b737cc179eb2354a2dcd16087d4trawick out of available file descriptors (sometimes called <cite>file
fb18194cd0e59b737cc179eb2354a2dcd16087d4trawick handles</cite>) if each Virtual Host specifies different log
fb18194cd0e59b737cc179eb2354a2dcd16087d4trawick files. The total number of file descriptors used by Apache is
fb18194cd0e59b737cc179eb2354a2dcd16087d4trawick one for each distinct error log file, one for every other log
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick file directive, plus 10-20 for internal use. Unix operating
fb18194cd0e59b737cc179eb2354a2dcd16087d4trawick systems limit the number of file descriptors that may be used
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick by a process; the limit is typically 64, and may usually be
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick increased up to a large hard-limit.</p>
61a4b32b1032d530e84e1131cb803f803acf7461trawick <p>Although Apache attempts to increase the limit as required,
61a4b32b1032d530e84e1131cb803f803acf7461trawick this may not work if:</p>
61a4b32b1032d530e84e1131cb803f803acf7461trawick <li>Your system does not provide the <code>setrlimit()</code>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick system call.</li>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <li>The <code>setrlimit(RLIMIT_NOFILE)</code> call does not
f6ba728fd666800e11b36452f7ad76ec5fcff653trawick function on your system (such as Solaris 2.3)</li>
f6ba728fd666800e11b36452f7ad76ec5fcff653trawick <li>The number of file descriptors required exceeds the hard
f6ba728fd666800e11b36452f7ad76ec5fcff653trawick limit.</li>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <li>Your system imposes other limits on file descriptors,
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick such as a limit on stdio streams only using file descriptors
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick below 256. (Solaris 2)</li>
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick <li>Reduce the number of log files; don't specify log files
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick in the <directive type="section" module="core">VirtualHost</directive>
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick sections, but only log to the main log files. (See <a
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick href="#splitlogs">Splitting up your log files</a>, below, for more
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick information on doing this.)</li>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick If you system falls into 1 or 2 (above), then increase the
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick file descriptor limit before starting Apache, using a
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick script like
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick ulimit -S -n 100<br />
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick exec httpd</code>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick href="/misc/descriptors.html">Descriptors and Apache</a>
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick document containing further details about file descriptor
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick problems and how they can be solved on your operating
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick system.</p>
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick<section id="splitlogs"><title>Splitting up your log files</title>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick<p>If you want to log multiple virtual hosts to the same log file, you
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawickmay want to split up the log files afterwards in order to run
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawickstatistical analysis of the various virtual hosts. This can be
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawickaccomplished in the following manner.</p>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick<p>First, you will need to add the virtual host information to the log
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawickentries. This can be done using the <directive module="mod_log_config">
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawickLogFormat</directive>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawickdirective, and the <code>%v</code> variable. Add this to the beginning
61a4b32b1032d530e84e1131cb803f803acf7461trawickof your log format string:</p>
61a4b32b1032d530e84e1131cb803f803acf7461trawickLogFormat "%v %h %l %u %t \"%r\" %>s %b" vhost<br />
61a4b32b1032d530e84e1131cb803f803acf7461trawick<p>This will create a log file in the common log format, but with the
61a4b32b1032d530e84e1131cb803f803acf7461trawickcanonical virtual host (whatever appears in the
61a4b32b1032d530e84e1131cb803f803acf7461trawick<directive module="core">ServerName</directive> directive) prepended to
61a4b32b1032d530e84e1131cb803f803acf7461trawickeach line. (See <directive
61a4b32b1032d530e84e1131cb803f803acf7461trawickmodule="mod_log_config">Custom Log Formats</directive> for
61a4b32b1032d530e84e1131cb803f803acf7461trawickmore about customizing your log files.)</p>
61a4b32b1032d530e84e1131cb803f803acf7461trawick<p>When you wish to split your log file into its component parts (one
61a4b32b1032d530e84e1131cb803f803acf7461trawickfile per virtual host) you can use the program <code><a
61a4b32b1032d530e84e1131cb803f803acf7461trawickhref="/programs/other.html">split-logfile</a></code> to accomplish
61a4b32b1032d530e84e1131cb803f803acf7461trawickthis. You'll find this program in the <code>support</code> directory
61a4b32b1032d530e84e1131cb803f803acf7461trawickof the Apache disribution.</p>
61a4b32b1032d530e84e1131cb803f803acf7461trawick<p>This program, when run with the name of your vhost log file, will
61a4b32b1032d530e84e1131cb803f803acf7461trawickgenerate one file for each virtual host that appears in your log file.
61a4b32b1032d530e84e1131cb803f803acf7461trawickEach file will be called <code>hostname.log</code>.</p>
61a4b32b1032d530e84e1131cb803f803acf7461trawick</manualpage>