Apache Cookbook offers you updated solutions to the problems you're likely to encounter with the new versions of Apache.
Chapter 1. Installation
Recipe 1.1. Installing from Red Hat Linux's Packages
Section 1.2. Installing from Debian Packages
Recipe 1.3. Installing Apache on Windows
Recipe 1.4. Downloading the Apache Sources
Recipe 1.5. Building Apache from the Sources
Recipe 1.6. Installing with ApacheToolbox
Recipe 1.7. Starting, Stopping, and Restarting Apache
Recipe 1.8. Uninstalling Apache
Section 1.9. Which Version of Apache to Use
Recipe 1.10. Upgrading Using config.nice
Recipe 1.11. Starting Apache at Boot
Recipe 1.12. Useful configure Options
Recipe 1.13. Finding Apache's Files
Chapter 2. Adding Common Modules
Recipe 2.1. Installing a Generic Third-Party Module
Recipe 2.2. Installing mod_dav on a Unixish System
Recipe 2.3. Installing mod_dav on Windows
Recipe 2.4. Installing mod_perl on a Unixish System
Recipe 2.5. Installing mod_php on a Unixish System
Recipe 2.6. Installing mod_php on Windows
Recipe 2.7. Installing mod_ssl
Recipe 2.8. Finding Modules Using modules.apache.org
Recipe 2.9. Installing mod_security
Recipe 2.10. Why Won't This Module Work?
Chapter 3. Logging
Recipe 3.1. Getting More Details in Your Log Entries
Recipe 3.2. Getting More Detailed Errors
Recipe 3.3. Logging POST Contents
Recipe 3.4. Logging a Proxied Client's IP Address
Recipe 3.5. Logging Client MAC Addresses
Recipe 3.6. Logging Cookies
Recipe 3.7. Not Logging Image Requests from Local Pages
Recipe 3.8. Rotating Logfiles at a Particular Time
Recipe 3.9. Rotating Logs on the First of the Month
Recipe 3.10. Logging Hostnames Instead of IP Addresses
Recipe 3.11. Maintaining Separate Logs for Each Virtual Host
Recipe 3.12. Logging Proxy Requests
Recipe 3.13. Logging Errors for Virtual Hosts to Multiple Files
Recipe 3.14. Logging Server IP Addresses
Recipe 3.15. Logging the Referring Page
Recipe 3.16. Logging the Name of the Browser Software
Recipe 3.17. Logging Arbitrary Request Header Fields
Recipe 3.18. Logging Arbitrary Response Header Fields
Section 3.19. Logging Activity to a MySQL Database
Section 3.20. Logging to syslog
Section 3.21. Logging User Directories
Chapter 4. Virtual Hosts
Recipe 4.1. Setting Up Name-Based Virtual Hosts
Recipe 4.2. Designating One Name-Based Virtual Host as the Default
Recipe 4.3. Setting Up Address-Based Virtual Hosts
Recipe 4.4. Creating a Default Address-Based Virtual Host
Recipe 4.5. Mixing Address-Based and Name-Based Virtual Hosts
Recipe 4.6. Mass Virtual Hosting with mod_vhost_alias
Recipe 4.7. Mass Virtual Hosting Using Rewrite Rules
Recipe 4.8. Logging for Each Virtual Host
Recipe 4.9. Splitting Up a Logfile
Recipe 4.10. Port-Based Virtual Hosts
Recipe 4.11. Displaying the Same Content on Several Addresses
Section 4.12. Defining Virtual Hosts in a Database
Chapter 5. Aliases, Redirecting, and Rewriting
Recipe 5.1. Mapping a URL to a Directory
Recipe 5.2. Creating a New URL for Existing Content
Recipe 5.3. Giving Users Their Own URLs
Recipe 5.4. Aliasing Several URLs with a Single Directive
Recipe 5.5. Mapping Several URLs to the Same CGI Directory
Recipe 5.6. Creating a CGI Directory for Each User
Recipe 5.7. Redirecting to Another Location
Recipe 5.8. Redirecting Several URLs to the Same Destination
Recipe 5.9. Permitting Case-Insensitive URLs
Recipe 5.10. Showing Highlighted PHP Source without Symlinking
Recipe 5.11. Replacing Text in Requested URLs
Recipe 5.12. Rewriting Path Information to CGI Arguments
Recipe 5.13. Denying Access to Unreferred Requests
Recipe 5.14. Redirecting Unreferred Requests to an Explanation Page
Recipe 5.15. Rewriting Based on the Query String
Recipe 5.16. Redirecting All—or Part—of Your Server to SSL
Recipe 5.17. Turning Directories into Hostnames
Recipe 5.18. Redirecting All Requests to a Single Host
Recipe 5.19. Turning Document Names into Arguments
Recipe 5.20. Rewriting Elements between Path and Query String
Recipe 5.21. Rewriting a Hostname to a Directory
Recipe 5.22. Turning URL Segments into Query Arguments
Recipe 5.23. Using AliasMatch, ScriptAliasMatch, and RedirectMatch
Chapter 6. Security
Recipe 6.1. Using System Account Information for Web Authentication
Recipe 6.2. Setting Up Single-Use Passwords
Recipe 6.3. Expiring Passwords
Recipe 6.4. Limiting Upload Size
Recipe 6.5. Restricting Images from Being Used Off-Site
Recipe 6.6. Requiring Both Weak and Strong Authentication
Recipe 6.7. Managing .htpasswd Files
Recipe 6.8. Making Password Files for Digest Authentication
Recipe 6.9. Relaxing Security in a Subdirectory
Recipe 6.10. Lifting Restrictions Selectively
Recipe 6.11. Authorizing Using File Ownership
Recipe 6.12. Storing User Credentials in a MySQL Database
Recipe 6.13. Accessing the Authenticated Username
Recipe 6.14. Obtaining the Password Used to Authenticate
Recipe 6.15. Preventing Brute-Force Password Attacks
Recipe 6.16. Using Digest Versus Basic Authentication
Recipe 6.17. Accessing Credentials Embedded in URLs
Recipe 6.18. Securing WebDAV
Recipe 6.19. Enabling WebDAV Without Making Files Writable by the Web User
Recipe 6.20. Restricting Proxy Access to Certain URLs
Recipe 6.21. Protecting Files with a Wrapper
Recipe 6.22. Protecting Server Files from Malicious Scripts
Recipe 6.23. Setting Correct File Permissions
Recipe 6.24. Running a Minimal Module Set
Recipe 6.25. Restricting Access to Files Outside Your Web Root
Recipe 6.26. Limiting Methods by User
Recipe 6.27. Restricting Range Requests
Section 6.28. Rebutting DoS Attacks with mod_evasive
Section 6.29. Chrooting Apache with mod_security
Section 6.30. Migrating to 2.2 Authentication
Recipe 6.31. Blocking Worms with mod_security
Recipe 6.32. Mixing Read-Only and Write Access to a Subversion Repository
Recipe 6.33. Using Permanent Redirects to Obscure Forbidden URLs
Chapter 7. SSL
Recipe 7.1. Installing SSL
Section 7.2. Installing SSL on Windows
Recipe 7.3. Generating Self-Signed SSL Certificates
Recipe 7.4. Generating a Trusted CA
Recipe 7.5. Serving a Portion of Your Site via SSL
Recipe 7.6. Authenticating with Client Certificates
Section 7.7. SSL Virtual Hosts
Section 7.8. Wildcard Certificates
Chapter 8. Dynamic Content
Recipe 8.1. Enabling a CGI Directory
Recipe 8.2. Enabling CGI Scripts in Non-ScriptAliased Directories
Recipe 8.3. Specifying a Default Document in a CGI Directory
Recipe 8.4. Using Windows File Extensions to Launch CGI Programs
Recipe 8.5. Using Extensions to Identify CGI Scripts
Recipe 8.6. Testing that CGI Is Set Up Correctly
Recipe 8.7. Reading Form Parameters
Recipe 8.8. Invoking a CGI Program for Certain Content Types
Recipe 8.9. Getting SSIs to Work
Recipe 8.10. Displaying Last Modified Date
Recipe 8.11. Including a Standard Header
Recipe 8.12. Including the Output of a CGI Program
Recipe 8.13. Running CGI Scripts as a Different User with suexec
Recipe 8.14. Installing a mod_perl Handler from CPAN
Recipe 8.15. Writing a mod_perl Handler
Recipe 8.16. Enabling PHP Script Handling
Recipe 8.17. Verifying PHP Installation
Recipe 8.18. Parsing CGI Output for Server Side Includes
Recipe 8.19. Parsing ScriptAlias Script Output for Server-Side Includes
Recipe 8.20. Getting mod_perl to Handle All Perl Scripts
Recipe 8.21. Enabling Python Script Handling
Chapter 9. Error Handling
Recipe 9.1. Handling a Missing Host Field
Recipe 9.2. Changing the Response Status for CGI Scripts
Recipe 9.3. Customized Error Messages
Recipe 9.4. Providing Error Documents in Multiple Languages
Recipe 9.5. Redirecting Invalid URLs to Some Other Page
Recipe 9.6. Making Internet Explorer Display Your Error Page
Recipe 9.7. Notification on Error Conditions
Chapter 10. Proxies
Recipe 10.1. Securing Your Proxy Server
Recipe 10.2. Preventing Your Proxy Server from Being Used as an Open Mail Relay
Recipe 10.3. Forwarding Requests to Another Server
Recipe 10.4. Blocking Proxied Requests to Certain Places
Recipe 10.5. Proxying mod_perl Content to Another Server
Recipe 10.6. Configuring a Caching Proxy Server
Recipe 10.7. Filtering Proxied Content
Recipe 10.8. Requiring Authentication for a Proxied Server
Section 10.9. Load Balancing with mod_proxy_balancer
Section 10.10. Proxied Virtual Host
Section 10.11. Refusing to Proxy FTP
Chapter 11. Performance
Recipe 11.1. Determining How Much Memory You Need
Recipe 11.2. Benchmarking Apache with ab
Recipe 11.3. Tuning KeepAlive Settings
Recipe 11.4. Getting a Snapshot of Your Site's Activity
Recipe 11.5. Avoiding DNS Lookups
Recipe 11.6. Optimizing Symbolic Links
Recipe 11.7. Minimizing the Performance Impact of .htaccess Files
Recipe 11.8. Disabling Content Negotiation
Recipe 11.9. Optimizing Process Creation
Recipe 11.10. Tuning Thread Creation
Recipe 11.11. Caching Frequently Viewed Files
Recipe 11.12. Distributing Load Evenly Between Several Servers
Recipe 11.13. Caching Directory Listings
Recipe 11.14. Speeding Up Perl CGI Programs with mod_perl
Section 11.15. Caching Dynamic Content
Chapter 12. Directory Listings
Recipe 12.1. Generating Directory/Folder Listings
Section 12.2. Display a Standard Header and Footer on Directory Listings
Recipe 12.3. Applying a Stylesheet
Recipe 12.4. Hiding Things from the Listing
Recipe 12.5. Searching for Certain Files in a Directory Listing
Recipe 12.6. Sorting the List
Section 12.7. Allowing a Client-Specified Sort Order
Recipe 12.8. Specifying How the List Will Be Formatted
Recipe 12.9. Allowing the Client to Specify the Formatting
Recipe 12.10. Adding Descriptions to Files
Recipe 12.11. Autogenerated Document Titles
Recipe 12.12. Changing the Listing Icons
Recipe 12.13. Listing the Directories First
Recipe 12.14. Ordering by Version Number
Recipe 12.15. Allowing the End User to Specify Version Sorting
Section 12.16. Complete User Control of Output
Section 12.17. Don't Allow the End User to Modify the Listing
Recipe 12.18. Suppressing Certain Columns
Section 12.19. Showing Forbidden Files
Recipe 12.20. Aliases in Directory Listings
Chapter 13. Miscellaneous Topics
Recipe 13.1. Placing Directives Properly
Recipe 13.2. Renaming .htaccess Files
Recipe 13.3. Generating Directory/Folder Listings
Recipe 13.4. Solving the "Trailing Slash" Problem
Recipe 13.5. Setting the Content-Type According to Browser Capability
Recipe 13.6. Handling Missing Host: Header Fields
Recipe 13.7. Alternate Default Document
Recipe 13.8. Setting Up a Default "Favicon"
Recipe 13.9. Directory Listings in ScriptAliased Directories
Recipe 13.10. Enabling .htaccess Files
Recipe 13.11. Converting IBM/Lotus Server-Side Includes to Apache
Appendix A. Using Regular Expressions in Apache
Section A.1. What Directives Use Regular Expressions?
Appendix B. Troubleshooting
Section B.1. Troubleshooting Methodology
Section B.2. Debugging the Configuration
Section B.3. Debugging Premature End of Script Headers
Section B.4. Common Problems on Windows
Section B.5. Fixing Build-Time Error Messages
Section B.6. Getting Server-Side Includes to Work
Section B.7. Debugging Rewrites That Result in "Not Found" Errors
Section B.8. .htaccess Files Having No Effect
Section B.9. Address Already in Use
The Apache Web server is a remarkable piece of software. The basic package distributed by the Apache Software Foundation is quite complete and very powerful, and a lot of effort has gone into keeping it from suffering software bloat. One facet of the package makes it especially remarkable: it includes extensibility by design. In short, if the Apache package right out of the box does not do what you want, you can generally extend it so that it does. Dozens of extensions (called modules) are included as part of the package distributed by the Apache Software Foundation. And if one of these doesn't meet your needs, with several million users out there, there is an excellent chance someone else has already done your work for you, someone who has concocted a recipe of changes or enhancements to the server that will satisfy your requirements.
This book is a collection of these recipes. Its sources include tips from the firehose of the Usenet newsgroups, the Apache FAQ, Apache-related mailing lists, mail containing "how-to" questions, questions and problems posed on IRC chat channels, and volunteered submissions.
All of the items in this book come from real-life situations, encountered either by us or by other people who have asked for our help. The topics range from basic compilation of the source code to complex problems involving the treatment of URLs that require SSL encryption.
We've collected more than a hundred different problems and their solutions, largely based on how often they occurred, and have grouped them roughly by subject as shown in Section P.1.
Primarily, these recipes are useful to webmasters who are responsible for the entire server; however, many are equally applicable to users who want to customize the behavior in their own Web directories through the use of .htaccess files.
We've written the Apache Cookbook to be a practical reference, rather than a theoretical discourse: reading it recipe by recipe, chapter by chapter, isn't going to reveal a plot ("Roy Fielding in the Library with an RFC!"[1] ). It's intended to provide point solutions to specific problems, located through the table of contents or the index.