Objective

This page is intended to share common issues related to Apache and also as a start-up guide for new users.

The Apache configuration file is: httpd.conf

DocumentRoot - Default directory location

Web pages are served from the directory as configured by the DocumentRoot directive specified in the httpd.conf configuration file. The default directory location for various linux flavors is:

  • Red Hat 7.x-9, CentOS 4: /var/www/html/
  • Suse 10.x: /srv/www/htdocs/

The apache allows one to have multiple user accounts under one domain and references them as: http://www.domain.com/~username/. The user can place his files in the public_html directory under his profile. The files should be readable for the user apache. These files should not be owned by user apache as this is the process owner of the httpd web server daemon.

ServerRoot

ServerRoot is the directory under which the server's configuration, error, and log files are kept.

Giving directory access

One can (should) limit apache's view of the file system to only necessary directories. This can be done with the directory statement as follows.

<Directory />

Options None AllowOverride None

</Directory>

The '/' means root. Usually its a good practice to deny access to root, and then grant access to the necessary directories.

.htaccess files:

.htaccess files (or "distributed configuration files") provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof. The .htaccess file should only be used when one doesn't have access to the main configuration files. It should not be used when performance is an issue. What you can put in these files is determined by the AllowOverride directive. If a directive is permitted in a .htaccess file, the documentation for that directive will contain an Override section, specifying what value must be in AllowOverride in order for that directive to be permitted.

AllowOverride

  • When this directive is set to None, then .htaccess files are completely ignored. In this case, the server will not even attempt to read .htaccess files in the filesystem.
  • When this directive is set to All, then any directive which has the .htaccess Context is allowed in .htaccess files.

For more info check: http://httpd.apache.org/docs/trunk/mod/core.html#allowoverride

KeepAlive and KeepAliveTimeout

KeepAlive: A Keep-Alive connection with an HTTP/1.0 client can only be used when the length of the content is known in advance. For HTTP/1.1 clients, persistent connections are the default unless otherwise specified. KeepAliveTimeout: In a name-based virtual host context, the value of the first defined virtual host (the default host) in a set of NameVirtualHost will be used. The other values will be ignored.

Error Pages

One can create custom error pages by specifying ErrorDocument 40x /Error40x.html In the above example apache will look for the error page within DocumentRoot directory. One can specify other directories as well.

pid file

The file in which the server records its process id when it starts. The server stop script looks for this pid for stopping the server. example: PidFile /var/run/httpd.pid

Server Side Includes

!Server Side Includes (SSI) are directives that are placed in HTML pages, and evaluated on the server while the pages are being served. They let you add dynamically generated content to an existing HTML page, without having to serve the entire page via a CGI program, or other dynamic technology. SSI is a great way to add small pieces of information, such as the current time, page counter etc... . If one needs to add more dynamic content then, one should look for other alternatives like CGI. Pre-req module: mod_include Add directive Options +Includes to enable SSI. For more info check: http://httpd.apache.org/docs/2.0/howto/ssi.html

Virtual Hosts

Rewrite Rules

It uses mod_rewrite module also known as URL rewrite engine. This module uses a rule-based rewriting engine (based on a regular-expression parser) to rewrite requested URLs on the fly. Not surprisingly it requires knowledge of regular expressions, at least introductory. For more information about rewrite rules please refer to apache documentation. A good place for regular expressions reference is http://www.perl.com/doc/manual/html/pod/perlre.html .

robots.txt

Errors

  • Error [Timestamp] [error] [client ] File does not exist: /htdocs . Possible problem: If there is no DocumentRoot defined Apache automatically uses /htdocs as the document root. Check for DocumentRoot in virtual host configuration and/or main configuration file.

Load and performance testing

Apache !JMeter is a desktop application for load and performance testing of web applications. More info can be found at: http://jakarta.apache.org/jmeter/

Reference: 1.http://httpd.apache.org/docs/2.0