|
|
Made to Measure : Apache Web Server Customization
You are here: irt.org | Articles | Linux & Apache | Made to Measure : Apache Web Server Customization Published on: Sunday 22nd August 1999 By: Pankaj Kamthan
IntroductionApache Web server originated from a series of "patches" to the NCSA Web server. As benchmark comparisons provided by Netcraft surveys show, its use has grown steadily over the last five years and it is the most popular Web server in use today. A comparison of features of a large number of Web servers currently in use is available at WebServer Compare. A quick overview of features of Apache is available here. An Overview of Apache ModulesOne of the key features of Apache is its "modular" architecture which makes is possible for anyone to add new functions to the server. In fact, most of the code that comes as part of the Apache distribution is in the form of modules, and can be removed or replaced. It has a generalized interface to modules that extends the functionality of the base package. There are a large number of modules now written for Apache. Besides those included with the distribution, modules are also written to add functions not already in the code, or to do things which are needed on some sites but are not of widespread use. Some of these modules are written by Apache developers. Most of them, however, are written by other users of Apache who want to adapt its functionality for their needs. In this article, we will look at a range of Apache modules which can be configured in the Apache server, and the range of advantages they offer. We will restrict ourselves specifically to UNIX-type and occassionally to Windows 9x/NT systems, though the basic ideas carry over to other systems. Standard ModulesThere are various modules that come with the Apache distribution. All the standard Apache modules currently shipped (provided you downloaded the source and not the binary) reside in Apache's src directory. However, only selected modules are compiled in by default. For example, mod_cgi (for invoking CGI scripts) is and mod_example (for demonstrating Apache API) is not compiled in by default. A list of standard modules, the ones that are compiled-in by default and the ones that are not compiled-in, is given in Appendix I. Customizing Standard ModulesThere are two reasons due to which you might like to customize your server:
It is quite simple to enable or disable a standard module. All you need to do is suitably edit the Configuration file in the src directory. On UNIX-type systems, module selection lines begin with AddModule and have the format:
or
Uncommenting/commenting will enable/disable a module on compilation. Note the following:
Suppose you have installed a Apache binary for Windows 9x/NT systems. It comes with a selected few standard modules in form of DLLs which are kept in the modules directory. You can obtain other module DLLs (such as for mod_perl) which you can enable by placing them in modules directory, and restarting Apache. The Windows version of Apache is configured to be able to load dynamic objects by default. A Tour of Standard ModulesModules reflect the features supported by Apache. Therefore, knowing the list of modules available is useful in order to take advantage of those features. As an example, Apache supports Common Gateway Interface (CGI) scripts through the module mod_cgi, Server-Side Includes (SSI) and eXtended Server-Side Includes (XSSI) through the module mod_include, (server-side) image maps through the module mod_imap, content negotiation through the module mod_negotiation, cookies through the module mod_usertrack, URL-to-URL and URL-to-filename mapping using mod_rewrite, and correcting minor spelling errors in URL through the module mod_speling. Appendix I lists modules that can be useful for other applications. Nonstandard ModulesThere are a variety of nonstandard or "third-party" modules developed by users around the world. They can be found in the Module Registry Database. Adding a Nonstandard ModuleTo add a module to Apache, you need to carry out the following steps:
Obtaining Nonstandard ModulesFirst, you will need to download the module. Here is a CGI referral search gateway to the Apache Module Registry Database. You may separate keywords with the boolean conditionals AND and OR to control your search results. Search without parameters returns a complete listing of the database. A selected list of nonstandard modules is given in Appendix II. Most modules come as a single of the form mod_*.c. Place this file in Apache's src/modules/extra directory. If the module comes as more than one file, (for example, the mod_php module) follow the instructions that come with the module. Configuring ApacheOnce you have obtained the module source, Apache needs to be configured so that it will compile this code. To do that, edit the Configuration file in the src directory, and add a suitable AddModule line:
The last argument on the AddModule line is the filename of the module, with the .c replaced by .o. After editing Configuration file, re-compile Apache by typing the following:
Finally, stop (if you are running) the server,for example, with:
install the new HTTPD executable, and start it, for example, with:
It is usually more convenient to have aliases for starting and stopping commands. For Windows 9x/NT, after downloading a module DLL (such as for coldfusion_module), place it in the modules directory. Then edit the httpd.conf file to include the following directive:
and restart Apache. A Tour of Nonstandard ModulesThe power that comes with the standard modules is further enhanced by the availability (mostly free) of nonstandard modules written for various purposes by users around the world. Arguably, the ones that are most useful from a developer's viewpoint, are embedded language interpreter modules, for example, mod_perl, which embeds the Perl language interpreter, or mod_pyapache, which embeds the Python language interpreter. They open up an entire host of new applications which have previously been nonexistent. Often scripting languages such as Perl and Python are used to write CGI scripts but tend to suffer from performance problems. With the use of corresponding modules mentioned above, one can have significant performance gain when using CGI scripts written in these languages and running them under Apache. These CGI scripts can now also access Apache internals. Besides that, one can even write Apache modules (which have traditionally written in C) in these languages. With the module mod_javascript, one can now take advantage of server-side JavaScript, which till now has only been available in Netscape FastTrack and Enterprise servers. Apart from embedded interpreter modules, there are various other useful modules: apache_ssl, which provides Secure Socket Layer (SSL) protocol extension in Apache and makes it run as a secure server; mod_fastcgi for FastCGI, which speeds up CGI script via co-processing; and mod_auth_msql and mod_auth_mysql for authentication against mSQL and mySQL databases, respectively. Appendix II lists modules that can be useful for other applications. ConclusionOne of major powers of Apache come from the pool of modules it offers. This power can be unleashed by knowing what this pool consists of, how it can be configured, and how it can be extended. References
Appendix I : List of Standard ModulesThis appendix (alphabetically) lists of all of the standard modules that are part of the current (version 1.3.x) Apache distribution. Table 1 the modules that are compiled-in by default and Table 2 lists the ones which are not.
Table 1. Apache Standard Modules Compiled-In by Default.
Table 2. Apache Standard Modules Not Compiled-In by Default. Appendix II : List of Nonstandard ModulesThis appendix is a list of some nonstandard Apache modules. The selection is biased towards modules for programming language support and Web site administration. See Table 3.
Table 3. Apache Nonstandard Modules. View the profile on Pankaj Kamthan and the list of other Articles by Pankaj Kamthan. |
-- div -->
|