From Habari Project
Apache is used to host both dynamic and static content served up under hp.o and its subdomains.
The Apache configuration follows a standard Debian / Ubuntu pattern.
Do not edit the default apache2.conf file. Future changes may be made in the Apache package that require configuration updates. Rather than manually needing to consolidate these changes the default apache2.conf file can be used without worry.
All changes should be added in either the /etc/apache2/httpd.conf file, in individual /etc/apache2/conf.d/* override files, or the respective vhost configuration.
The bulk of the configuration changes for basic server operation are done in httpd.conf.
In general it is preferred not to specify an Apache configuration directive if the value would be the same as the default, although in some cases it is done for clarity. When making any changes, check the Apache Quick Reference list to note the default value.
Generic Server Config
Config File: /etc/apache2/httpd.conf
The ServerName value sets the name by which the server refers to itself when building URLs.
The Timeout value defines how long Apache will wait for requests to finish.
Generally if a request has not completed in a very short period of time it's dead. Keeping this high can potentially result in a lot of "hung" connections that lock up processes and prevent other clients from accessing the server.
This value is pretty common, particularly on lower-memory installations where freeing up processes quickly is important, but doesn't hold any specific significance. A little higher, a little lower, chances are good it won't really matter.
Turning on persistent HTTP connections allows the same TCP connection to be used for multiple requests from a client. Since most modern web requests rarely involve loading a single asset from the server, this can greatly increase the performance for clients.
Default: The default value is 'On', so this is redundant and for clarity that the following KeepAliveTimeout value is actually reflected.
Keep Alive Timeout
The KeepAliveTimeout value defines how long Apache will keep a connection open after a client makes a request waiting for it to make additional request.
Keeping too many connections open can degrade performance and most subsequent requests (such as for static resources after a page request) are made within a very short period of time after the initial request, so having a high timeout value makes little sense.
Config File: /etc/apache2/conf.d/deflate
The Apache Deflate module compresses output from the server dynamically, saving bandwidth and speeding up transfers.
Compression only works on textual contents types, so it is configured for a large number of types:
Not all of these types are used and some of them are considered "invalid" but included for comprehensive coverage since there is no downside.
Config File: /etc/apache2/conf.d/expires
The Apache Expires module sets the HTTP Expires header value so that clients will cache as many resources as possible.
Similar to the Deflate module, expiration is generally configured by content type:
All the content types are set to have their Expires header set to "access plus 1 month", caching them for a month.
Config File: /etc/apache2/httpd.conf
The Prefork MPM is used, so we're dealing with individual processes which are spawned for each request.
The StartServers value defines the number of processes initially created when starting Apache.
Min Spare Servers
The MinSpareServers value defines the minimum number of idle processes that we'll always keep around.
Max Spare Servers
The MaxSpareServers value defines the maximum number of idle processes that we'll always keep around.
In instances where the Apache configuration has set memory requirements and the server has an abundance of spare memory, there's absolutely no reason to reduce this value. Keeping the extra processes around saves time re-creating a new process when a request comes in.
Max Requests Per Child
The MaxRequestsPerChild value defines the maximum number of requests each process will handle before being restarted.
"Cycling" processes on a regular basis is a performance hit but allows for us to recover RAM from child processes and reduce the overall footprint of Apache. 100 was chosen through process of elimination - it doesn't significantly impact the performance of the server by recycling processes but keeps Apache memory usage predictably low.
Under the Prefork MPM the MaxClients value defines the maximum number of simultaneous processes that will be generated. Each process can handle a single simultaneous connection, any connections over this number will be queued until a process is idle to handle it, but requires a certain amount of memory.
Go too low and client connections will be needlessly spooled, go too high and Apache could eat all the RAM on the box causing the system to swap to disk excessively and dragging the system down into an abysmal well of unresponsiveness.
The MaxClients directive is the most important value you can tune on an Apache configuration so the math is of significant importance.
As noted on the Resource Analysis page, MySQL can easily be expected to eat 180M of RAM out of the total 1G on the box. Trac is currently configured to use 4 FCGI processes. Averaging somewhere between 50 and 70M each, Trac can be expected to use up to 256M of RAM (actually about 280M).
1G - 180M (MySQL) - 256M (Trac) = 588M
Of the remaining 588, expect to allocate a chunk to the base system. For round numbers we'll aim high and assume 128M.
This leaves approximately 460M of RAM left to be allocated to Apache. Using the 50 - 55M per process averages from the Resource Analysis we can reasonably expect to run between 8.36 and 9.2 Apache processes at a time. Whole numbers only, so we should be able to handle a MaxClients value of 8 to 9.
Virtual hosts are stored in individual files within the directory /etc/apache2/sites-available. They are activated using the a2ensite command, which creates a link in /etc/apache2/sites-enabled.
The ServerAdmin should be set in each vhost to email@example.com. This account should, hopefully, be monitored.
The AllowOverride directive should always be configured to All. This allows each vhost to set its own Options declarations as needed simply by modifying the .htaccess file, rather than changing the vhost and restarting Apache.
Config File: /etc/apache2/sites-available/default
The Default virtual host sets up a few basics (like the SSL certificate and Named Virtual Servers) and serves as the "fallback" host, should a request not match any other configured virtual host.