Develop Apache HTTP Server Modules
Apache HTTP Server is one of the most iconic open source projects in human history. It’s also the world’s most used and respected web server. In this tutorial you’ll learn how to add your own features to it…
As of February 2010, Apache served over 54.46% of all websites and over 66% of the million busiest. It is available on a wide variety of platforms including Linux, Mac OS X, Windows and BSD. One of the key factors behind Apache HTTP Server’s success is its modular architecture. The Apache HTTP Server core is very simple and doesn’t do much. The default distribution of HTTP Server contains the core and a set of core Apache Modules that handle most of the web-server-related operations. This modular architecture presents several benefits. For example, instead of running the full server, one can enable only the modules that one will use; this way one can run the most efficient version of the HTTP Server without changing the server code. Another benefit of modular architecture is extensibility. Apache as a web server community implements a defined feature set approved by the community, but that may or may not be enough for everybody. With extensible architecture, anybody can extend Apache HTTP Server according to their needs by developing Apache modules.
As mentioned previously, Apache HTTP Server comes with several built-in modules. You can run the following command to find out the list of built-in (or compiled-in) modules:
$ apachectl -l
Names starting from mod_ are the actual modules that we are talking about and can be disabled or enabled using the httpd.conf file.
The vanilla distribution (when compiled with default options) of Apache HTTP Server (2.2.16) comes with the following important modules…
mod_authn_file.c: This provides a user authentication system using plain text files.
mod_authn_default.c: This module provides fallback for the authentication system. If you have not configured an authentication module, this module will reject any credential provided by user.
mod_authz_host.c: Provides group authentication based on host name or IP address
mod_authz_groupfile.c: Provides group authentication using plain text files.
mod_authz_user.c: Provides the base user authentication system.
mod_include.c: Processes the server-side include files.
mod_filter.c: This module enables smart, context-sensitive configuration of output content filters.
mod_log_config.c: Provides logging system for client request.
mod_env.c: Modifies the environment which is passed to CGI scripts and SSI pages.
mod_mime.c: Provides the valid MIME type of a file that is being served.
mod_autoindex.c: Generates directory indexes automatically, similar to the UNIX
mod_cgi.c: Provides support for CGI scripts.
mod_dir.c: Provides for ‘trailing slash’ redirects and serving directory index files.
mod_alias.c: Provides mapping support for file system directory and URL redirection.
mod_so.c: Provides support for module loading during server startup or restart.
Developing a ‘Hello World’ Apache Module
First of all perform the following steps to install Apache from source:
$ wget http://mirror.cloudera.com/apache//httpd/httpd-2.2.16.tar.gz $ tar xvfz http-* $ cd httpd* $ ./configure --prefix=$HOME/ludapache //This will install apache into ludapache folder in your home directory. $ make $ make install
By now you will have the Apache Web Server installed and configured to listen on default HTTP port, ie 80. On most of the UNIX systems, port 80 is reserved for the system web server and can only be run with root privileges. To run the web server in non-root mode we will need to make some changes to the Apache configuration file:
$ <HTTPD Direcotry>/conf/httpd.conf
In the following section, change ‘Listen 80’ to ‘Listen 3322’.
# Listen: Allows you to bind Apache to specific IP addresses and/or # ports, instead of the default. See also the <VirtualHost> # directive. # Change this to Listen on specific IP addresses as shown below to # prevent Apache from glomming onto all bound IP addresses. #Listen 220.127.116.11:80 Listen 3322