Friday, May 22, 2009

Apache HTTP Server: Configuration

Apache HTTP Server is a famous open source web server.  The default configuration file is located at “/etc/httpd/conf/httpd.conf”

Server Side Includes (SSI)

SSI (Server Side Includes) 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.

To enable SSI in Apache HTTP, add the following in conf file:

AddType text/html .shtml
AddHandler server-parsed .shtml

<Directory /data/www>
    Options +Includes

If the index file is a SSI file, you should add this line too:

DirectoryIndex index.html index.html.var index.shtml

Virtual Host Configuration

The term Virtual Host refers to the practice of maintaining more than one server on one machine, as differentiated by their apparent hostname. For example, it is often desirable for companies sharing a web server to have their own domains, with web servers accessible as and, without requiring the user to know any extra path information.

In order not to mess up the httpd.conf file, we may store the virtual host configuration in a separate file. (eg: /etc/httpd/conf/httpd-vhosts.conf)


NameVirtualHost *:80

<Directory /data/www>
    Options +Includes

<VirtualHost *:80>
    DocumentRoot /data/www
    ScriptAlias /cgi-bin/ /data/www/cgi-bin/ 

We then use Include directive in httpd.conf by adding a line near the VirtualHost section:

Include conf/httpd-vhosts.conf

Restart the Apache HTTP Server

Remember to restart the Apache HTTP Server for changes you did:

# service httpd restart