Apache Cookbook

Book description

Apache is far and away the most widely used web server platform in the world. Both free and rock-solid, it runs more than half of the world's web sites, ranging from huge e-commerce operations to corporate intranets and smaller hobby sites, and it continues to maintain its popularity, drawing new users all the time. If you work with Apache on a regular basis, you have plenty of documentation on installing and configuring your server, but where do you go for help with the day-to-day stuff, like adding common modules or fine-tuning your activity logging?The Apache Cookbook is a collection of problems, solutions, and practical examples for webmasters, web administrators, programmers, and everyone else who works with Apache. For every problem addressed in the book, there's a worked-out solution or "recipe"--short, focused pieces of code that you can use immediately. But this book offers more than cut-and-paste code. You also get explanations of how and why the code works, so you can adapt the problem-solving techniques to similar situations.The recipes in the Apache Cookbook range from simple tasks, such installing the server on Red Hat Linux or Windows, to more complex tasks, such as setting up name-based virtual hosts or securing and managing your proxy server. The two hundred plus recipes in the book cover additional topics such as:

  • Security
  • Aliases, Redirecting, and Rewriting
  • CGI Scripts, the suexec Wrapper, and other dynamic content techniques
  • Error Handling
  • SSL
  • Performance
The impressive collection of useful code in this book is a guaranteed timesaver for all Apache users, from novices to advanced practitioners. Instead of poking around mailing lists, online documentation, and other sources, you can rely on the Apache Cookbook for quick solutions to common problems, and then you can spend your time and energy where it matters most.

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. What’s in This Book
    2. Platform Notes
    3. Other Books
    4. Other Sources
    5. How This Book Is Organized
    6. Conventions Used in This Book
    7. We’d Like to Hear from You
    8. Acknowledgments
  2. 1. Installation
    1. 1.1. Installing from Red Hat Linux’s Packages
    2. 1.2. Installing Apache on Windows
    3. 1.3. Downloading the Apache Sources
    4. 1.4. Building Apache from the Sources
    5. 1.5. Installing with ApacheToolbox
    6. 1.6. Starting, Stopping, and Restarting Apache
    7. 1.7. Uninstalling Apache
  3. 2. Adding Common Modules
    1. 2.1. Installing a Generic Third-Party Module
    2. 2.2. Installing mod_dav on a Unixish System
    3. 2.3. Installing mod_dav on Windows
    4. 2.4. Installing mod_perl on a Unixish System
    5. 2.5. Installing mod_php on a Unixish System
    6. 2.6. Installing mod_php on Windows
    7. 2.7. Installing the mod_snake Python Module
    8. 2.8. Installing mod_ssl
  4. 3. Logging
    1. 3.1. Getting More Details in Your Log Entries
    2. 3.2. Getting More Detailed Errors
    3. 3.3. Logging POST Contents
    4. 3.4. Logging a Proxied Client’s IP Address
    5. 3.5. Logging Client MAC Addresses
    6. 3.6. Logging Cookies
    7. 3.7. Not Logging Image Requests from Local Pages
    8. 3.8. Logging Requests by Day or Hour
    9. 3.9. Rotating Logs on the First of the Month
    10. 3.10. Logging Hostnames Instead of IP Addresses
    11. 3.11. Maintaining Separate Logs for Each Virtual Host
    12. 3.12. Logging Proxy Requests
    13. 3.13. Logging Errors for Virtual Hosts to Multiple Files
    14. 3.14. Logging Server IP Addresses
    15. 3.15. Logging the Referring Page
    16. 3.16. Logging the Name of the Browser Software
    17. 3.17. Logging Arbitrary Request Header Fields
    18. 3.18. Logging Arbitrary Response Header Fields
    19. 3.19. Logging Activity to a MySQL Database
    20. 3.20. Logging to syslog
    21. 3.21. Logging User Directories
  5. 4. Virtual Hosts
    1. 4.1. Setting Up Name-Based Virtual Hosts
    2. 4.2. Designating One Name-Based Virtual Host as the Default
    3. 4.3. Setting Up Address-Based Virtual Hosts
    4. 4.4. Creating a Default Address-Based Virtual Host
    5. 4.5. Mixing Address-Based and Name-Based Virtual Hosts
    6. 4.6. Mass Virtual Hosting with mod_vhost_alias
    7. 4.7. Mass Virtual Hosting Using Rewrite Rules
    8. 4.8. SSL and Name-Based Virtual Hosts
    9. 4.9. Logging for Each Virtual Host
    10. 4.10. Splitting Up a LogFile
    11. 4.11. Port-Based Virtual Hosts
    12. 4.12. Displaying the Same Content on Several Addresses
  6. 5. Aliases, Redirecting, and Rewriting
    1. 5.1. Showing Highlighted PHP Source Without Symlinking
    2. 5.2. Mapping a URL to a Directory
    3. 5.3. Creating a New URL for Existing Content
    4. 5.4. Giving Users Their Own URL
    5. 5.5. Aliasing Several URLs with a Single Directive
    6. 5.6. Mapping Several URLs to the Same CGI Directory
    7. 5.7. Creating a CGI Directory for Each User
    8. 5.8. Redirecting to Another Location
    9. 5.9. Redirecting Several URLs to the Same Destination
    10. 5.10. Permitting Case-Insensitive URLs
    11. 5.11. Replacing Text in Requested URLs
    12. 5.12. Rewriting Path Information to CGI Arguments
    13. 5.13. Denying Access to Unreferred Requests
    14. 5.14. Rewriting Based on the Query String
    15. 5.15. Redirecting All—or Part—of Your Server to SSL
    16. 5.16. Turning Directories into Hostnames
    17. 5.17. Redirecting All Requests to a Single Host
    18. 5.18. Turning Document Names into Arguments
  7. 6. Security
    1. 6.1. Using System Account Information for Web Authentication
    2. 6.2. Setting Up Single-Use Passwords
    3. 6.3. Expiring Passwords
    4. 6.4. Limiting Upload Size
    5. 6.5. Restricting Images from Being Used Off-Site
    6. 6.6. Requiring Both Weak and Strong Authentication
    7. 6.7. Managing .htpasswd Files
    8. 6.8. Making Password Files for Digest Authentication
    9. 6.9. Relaxing Security in a Subdirectory
    10. 6.10. Lifting Restrictions Selectively
    11. 6.11. Authorizing Using File Ownership
    12. 6.12. Storing User Credentials in a MySQL Database
    13. 6.13. Accessing the Authenticated Username
    14. 6.14. Obtaining the Password Used to Authenticate
    15. 6.15. Preventing Brute-Force Password Attacks
    16. 6.16. Using Digest Versus Basic Authentication
    17. 6.17. Accessing Credentials Embedded in URLs
    18. 6.18. Securing WebDAV
    19. 6.19. Enabling WebDAV Without Making Files Writable by the Web User
    20. 6.20. Restricting Proxy Access to Certain URLs
    21. 6.21. Protecting Files with a Wrapper
    22. 6.22. Protecting All Files Except a Subset
    23. 6.23. Protecting Server Files from Malicious Scripts
    24. 6.24. Setting Correct File Permissions
    25. 6.25. Running a Minimal Module Set
    26. 6.26. Restricting Access to Files Outside Your Web Root
    27. 6.27. Limiting Methods by User
    28. 6.28. Restricting Range Requests
  8. 7. SSL
    1. 7.1. Installing SSL
    2. 7.2. Generating SSL Certificates
    3. 7.3. Generating a Trusted CA
    4. 7.4. Serving a Portion of Your Site via SSL
    5. 7.5. Authenticating with Client Certificates
  9. 8. Dynamic Content
    1. 8.1. Enabling a CGI Directory
    2. 8.2. Enabling CGI Scripts in Non-ScriptAliased Directories
    3. 8.3. Using Windows File Extensionsto Launch CGI Programs
    4. 8.4. Using Extensions to Identify CGI Scripts
    5. 8.5. Testing That CGI Is Set Up Correctly
    6. 8.6. Reading Form Parameters
    7. 8.7. Invoking a CGI Program for Certain Content Types
    8. 8.8. Getting SSIs to Work
    9. 8.9. Displaying Last Modified Date
    10. 8.10. Including a Standard Header
    11. 8.11. Including the Output of a CGI Program
    12. 8.12. Running CGI Scripts as a Different User with suexec
    13. 8.13. Installing a mod_perl Handler from CPAN
    14. 8.14. Writing a mod_perl Handler
    15. 8.15. Enabling PHP Script Handling
    16. 8.16. Verifying PHP Installation
  10. 9. Error Handling
    1. 9.1. Handling a Missing Host Field
    2. 9.2. Changing the Response Status for CGI Scripts
    3. 9.3. Customized Error Messages
    4. 9.4. Providing Error Documents in Multiple Languages
    5. 9.5. Redirecting Invalid URLs to Some Other Page
    6. 9.6. Making Internet Explorer Display Your Error Page
    7. 9.7. Notification on Error Conditions
  11. 10. Proxies
    1. 10.1. Securing Your Proxy Server
    2. 10.2. Preventing Your Proxy Server from Being Used as an Open Mail Relay
    3. 10.3. Forwarding Requests to Another Server
    4. 10.4. Blocking Proxied Requests to Certain Places
    5. 10.5. Proxying mod_perl Content to Another Server
    6. 10.6. Configuring a Caching Proxy Server
    7. 10.7. Filtering Proxied Content
    8. 10.8. Requiring Authentication for a Proxied Server
  12. 11. Performance
    1. 11.1. Determining How Much Memory You Need
    2. 11.2. Benchmarking Apache with ab
    3. 11.3. Tuning Keepalive Settings
    4. 11.4. Getting a Snapshot of Your Site’s Activity
    5. 11.5. Avoiding DNS Lookups
    6. 11.6. Optimizing Symbolic Links
    7. 11.7. Minimizing the Performance Impact of .htaccess Files
    8. 11.8. Disabling Content Negotiation
    9. 11.9. Optimizing Process Creation
    10. 11.10. Tuning Thread Creation
    11. 11.11. Caching Frequently Viewed Files
    12. 11.12. Sharing Load Between Servers Using mod_proxy
    13. 11.13. Distributing Load Evenly Between Several Servers
    14. 11.14. Caching Directory Listings
    15. 11.15. Speeding Up Perl CGI Programs with mod_perl
  13. 12. Miscellaneous Topics
    1. 12.1. Placing Directives Properly
    2. 12.2. Renaming .htaccess Files
    3. 12.3. Generating Directory/Folder Listings
    4. 12.4. Solving the “Trailing Slash” Problem
    5. 12.5. Setting the Content-Type According to Browser Capability
    6. 12.6. Handling Missing Host: Header Fields
    7. 12.7. Alternate Default Document
    8. 12.8. Setting Up a Default “Favicon”
  14. A. Using Regular Expressions in Apache
    1. A.1. What Directives Use Regular Expressions?
  15. B. Troubleshooting
    1. B.1. Troubleshooting Methodology
    2. B.2. Debugging the Configuration
    3. B.3. Debugging Premature End of Script Headers
    4. B.4. Common Problems on Windows
    5. B.5. Fixing Build-Time Error Messages
    6. B.6. Getting Server-Side Includes to Work
    7. B.7. Debugging Rewrites That Result in “Not Found” Errors
    8. B.8. .htaccess Files Having No Effect
    9. B.9. Address Already in Use
  16. About the Authors
  17. Colophon
  18. Copyright

Product information

  • Title: Apache Cookbook
  • Author(s): Ken Coar, Rich Bowen
  • Release date: November 2003
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9780596001919