00 0672322749 FM 3/18/04 1:49 PM Page i Apache A D M I N I S T R AT O R ’ S H A N D B O O K Rich Bowen Daniel Lõpez Ridruejo Allan Liska 800 East 96th St.,Indianapolis,Indiana,46240 USA 00 0672322749 FM 3/18/04 1:49 PM Page ii Apache Administrator’s Handbook ACQUISITIONSEDITORS Shelley Johnston Copyright 2002 by Sams Publishing Jennifer Kost-Barker All rights reserved. No part of this book shall be reproduced,stored in a DEVELOPMENTEDITOR retrieval system,or transmitted by any means,electronic,mechanical,photo- Heather Goodell copying,recording,or otherwise,without written permission from the pub- lisher. No patent liability is assumed with respect to the use of the information MANAGINGEDITOR contained herein. Although every precaution has been taken in the preparation Charlotte Clapp of this book,the publisher and authors assume no responsibility for errors or PROJECTEDITOR omissions. Nor is any liability assumed for damages resulting from the use of Elizabeth Finney the information contained herein. PRODUCTIONEDITOR International Standard Book Number:0-672-32274-9 Chip Gardner Library of Congress Catalog Card Number:2001092348 INDEXER Printed in the United States of America Aamir Burki First Printing:March 2002 PROOFREADER 05 04 03 4 3 2 Melissa Lynch Trademarks TECHNICALEDITORS Carlos Ramirez All terms mentioned in this book that are known to be trademarks or service Allan Liska marks have been appropriately capitalized. Sams Publishing cannot attest to Patrick Grip-Jansson the accuracy of this information. Use of a term in this book should not be TEAMCOORDINATOR regarded as affecting the validity of any trademark or service mark. Amy Patton Warning and Disclaimer INTERIORDESIGNER Anne Jones Every effort has been made to make this book as complete and as accurate as possible,but no warranty or fitness is implied. The information provided is on COVERDESIGNER an “as is”basis. The authors and the publisher shall have neither liability nor Aren Howell responsibility to any person or entity with respect to any loss or damages aris- PAGELAYOUT ing from the information contained in this book. Brad Lenser 00 0672322749 FM 3/18/04 1:49 PM Page iii Overview Introduction 1 Part I Installing and Configuring Your Apache Server 1 Getting Started 7 2 Acquiring and Installing Your Apache Server 17 3 Starting,Stopping,and Restarting 27 4 Configuration Directives 35 5 Configuration Utilities 53 6 .htaccessfiles—Per-Directory Configuration 71 7 Virtual Hosts 79 Part II Advanced Configuration Techniques 8 MIME and File Types 91 9 URL Mapping 101 10 Content Negotiation 109 11 Directory Indexing 117 12 Apache on Microsoft Windows 137 13 Performance Tuning 149 Part III Dynamic Content 14 Handlers and Filters 161 15 CGI Programs 175 16 Server-Side Includes 195 17 mod_perl 209 18 PHP 225 Part IV Security and Auditing 19 Apache Security 247 20 Security in Dynamic Content 267 21 Authentication,Authorization,and Access Control 283 22 SSL 301 23 Web Spiders 317 24 Logging 327 00 0672322749 FM 3/18/04 1:49 PM Page iv Part V Modules 25 Introduction to Apache Modules 349 26 Modules Included with Apache 357 27 Special-Purpose Apache Modules 369 Part VI Appendixes A The Apache Software License 377 B Configure Command-Line Options 381 C Regular Expressions 387 D mod_perlExample Code 391 E Apache History 395 F Where to Get More Information 399 Index 405 00 0672322749 FM 3/18/04 1:49 PM Page v Contents Introduction What Is Apache? ....................................................................................1 Why Use Apache? ..................................................................................1 Who Else Is Using Apache? ..................................................................1 Who Is This Book For? ..........................................................................2 What’s with the Quotes? ........................................................................3 Conventions Used in This Book ............................................................3 Errata,Updates,and More Information ..................................................3 Part I Installing and Configuring Your Apache Server 1 Getting Started 7 Choosing a Web Server ..........................................................................8 Compatibility Requirements ..............................................................8 Existing Knowledge ..........................................................................8 Executive Edict ..................................................................................8 The Customer ....................................................................................8 Hardware and Software Requirements ..................................................9 Connectivity ............................................................................................9 Should I Host Somewhere Else,or Do It Myself? ..............................10 Connectivity ....................................................................................10 Reliable Connection ........................................................................10 How Much Access Do You Need? ..................................................11 Questions To Ask Your ISP ..................................................................11 Shared Space,Dedicated Server,Colloc? ......................................11 What Happens When Something Goes Wrong? ............................12 Backups? ..........................................................................................12 Installing Software ..........................................................................12 FTP,Telnet,SCP,SSH:Getting Content To Your Site ........................13 Telnet and SSH—Connecting To the Server ..................................13 FTP and SCP—Getting Content To Your Server ............................14 Summary ..............................................................................................15 2 Acquiring and Installing Your Apache Server 17 Overview for the Impatient ..................................................................18 Where Do I Get It? ..............................................................................18 Unpacking the Source ..........................................................................19 The Source Tree ....................................................................................20 cgi-bin ............................................................................................20 conf..................................................................................................20 htdocs ..............................................................................................20 00 0672322749 FM 3/18/04 1:49 PM Page vi vi APACHEADMINISTRATOR’SHANDBOOK icons................................................................................................21 logs..................................................................................................21 src ..................................................................................................21 Installing Binary Distributions ............................................................21 Installing on Windows ....................................................................22 Binary Versus Source Installation ..................................................22 configure..............................................................................................23 Configuration Options ....................................................................24 Directory and Filenames ................................................................24 Host Type ........................................................................................24 Features and Packages ....................................................................25 A Default Installation ......................................................................25 make && make install ........................................................................25 Summary ..............................................................................................26 3 Starting, Stopping, and Restarting 27 apachectl..............................................................................................28 httpd ....................................................................................................29 Starting and Stopping with httpd ..................................................29 Command-Line Flags ......................................................................30 Starting on System Startup ..................................................................30 Microsoft Windows ..............................................................................31 Starting from the Command Line ..................................................32 Installing as a Service ......................................................................32 Starting and Stopping Your Apache Service ..................................32 Console Application ........................................................................33 Summary ..............................................................................................34 4 Configuration Directives 35 Configuration Files ..............................................................................36 Configuration File Syntax ....................................................................37 Directives ........................................................................................37 Sections ............................................................................................38 Comments ........................................................................................42 Specifying a Different Configuration File ............................................43 Testing Your Configuration ..................................................................43 Including Directories ......................................................................46 Options:Turning on Features ..............................................................47 General Syntax ................................................................................47 ExecCGI ............................................................................................47 FollowSymLinks ..............................................................................48 SymLinksIfOwnerMatch....................................................................49 Includes ..........................................................................................49 IncludesNOEXEC ..............................................................................49 00 0672322749 FM 3/18/04 1:49 PM Page vii vii CONTENTS Indexes ............................................................................................49 MultiViews ......................................................................................50 All ..................................................................................................50 None..................................................................................................50 Configuration Security Considerations ..........................................50 Summary ..............................................................................................51 5 Configuration Utilities 53 GUIs and Configuration Files ..............................................................54 Webmin ................................................................................................55 Existing Webmin Installation ..........................................................55 Installation ......................................................................................56 Starting Webmin ..............................................................................58 Using Webmin ................................................................................58 Comanche ............................................................................................64 Installation ......................................................................................65 Using Comanche ............................................................................66 Summary ..............................................................................................70 6 .htaccess files—Per-Directory Configuration 71 AccessFileName ....................................................................................72 AllowOverride ......................................................................................73 AuthConfig(Authentication) ..........................................................73 FileInfo ..........................................................................................74 Indexes ............................................................................................74 Limit................................................................................................75 Options ............................................................................................75 All ..................................................................................................75 None..................................................................................................75 Caveats and Limitations ......................................................................76 Performance ....................................................................................76 Security ............................................................................................77 Summary ..............................................................................................78 7 Virtual Hosts 79 IP-Based Virtual Hosts ..........................................................................80 Setting Up Multiple IP Addresses ..................................................80 Configuring the Virtual Host ..........................................................81 Name-Based Virtual Hosts ....................................................................82 Port-Based Virtual Hosts ......................................................................83 Bulk Virtual Hosting ............................................................................84 Per-vhostConfiguration Files ........................................................84 mod_vhost_alias ............................................................................85 Running Multiple Daemons ..................................................................87 Summary ..............................................................................................88 00 0672322749 FM 3/18/04 1:49 PM Page viii viii APACHEADMINISTRATOR’SHANDBOOK Part II Advanced Configuration Techniques 8 MIME and File Types 91 MIME and HTTP ..................................................................................92 MIME Types Configuration Directives ................................................92 MIME Types Configuration ............................................................93 Encoding ..............................................................................................95 AddEncoding ..................................................................................95 RemoveEncoding ............................................................................96 Character Sets and Languages ..............................................................96 AddCharset ......................................................................................97 RemoveCharset ................................................................................97 AddLanguage ....................................................................................97 RemoveLanguage ..............................................................................97 DefaultLanguage ............................................................................98 Files with Multiple Extensions ............................................................98 Handlers ................................................................................................98 Summary ..............................................................................................99 9 URL Mapping 101 Location ..............................................................................................102 Alias ..................................................................................................102 ScriptAlias ........................................................................................103 AliasMatchand ScriptAliasMatch ....................................................103 Redirect ............................................................................................104 RedirectMatch ..............................................................................105 RedirectTempand RedirectPermanent ........................................105 DocumentRoot ......................................................................................105 Error Documents ................................................................................106 URL Rewriting ..................................................................................107 Summary ............................................................................................107 10 Content Negotiation 109 Client Preference ................................................................................110 Accept Headers ..............................................................................111 Quality Factor ................................................................................111 Negotiation Methods ..........................................................................112 Type Map File ..............................................................................112 MultiViews ....................................................................................114 Noncompliant Browsers ....................................................................115 Caching ..............................................................................................116 Summary ............................................................................................116 00 0672322749 FM 3/18/04 1:49 PM Page ix ix CONTENTS 11 Directory Indexing 117 DirectoryIndex ..................................................................................118 Options +Indexes ..............................................................................119 IndexOptions—”Fancy”Indexing ....................................................119 IndexOptionsSyntax ....................................................................120 FancyIndexing ..............................................................................120 DescriptionWidth ........................................................................121 AddIcon ..........................................................................................121 FoldersFirst ................................................................................123 HTMLTable ......................................................................................123 Icon Dimensions ............................................................................123 IconsAreLinks ..............................................................................124 IgnoreClient..................................................................................124 NameWidth ......................................................................................124 ScanHTMLTitles ............................................................................125 SuppressColumnSorting ................................................................125 SuppressDescription ..................................................................126 SuppressHTMLPreamble..................................................................126 SuppressIcon ................................................................................126 SuppressLastModified..................................................................126 SuppressRules ..............................................................................126 SuppressSize ................................................................................127 TrackModified ..............................................................................127 VersionSort ..................................................................................127 AddDescription ..................................................................................128 Headers and Footers ..........................................................................129 Ignoring Files ......................................................................................129 Searching and Sorting ........................................................................130 Sorting in Version 1.3 ....................................................................130 Sorting in Version 2.0 ....................................................................131 IndexOrderDefault ......................................................................133 Examples ............................................................................................133 Example 1 ......................................................................................133 Example 2 ......................................................................................134 Indexing Security Concerns ................................................................134 Summary ............................................................................................134
Description: