Tải bản đầy đủ (.pdf) (793 trang)

apache server 2 bible

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (3.44 MB, 793 trang )

KABIR
If Apache Server 2 can do it, you can do it too . . .
Updated for the latest Apache release and packed with real-world examples, this all-in-one reference shows you
step by step how to take full advantage of Apache Server — and create a Web site that’s fast, secure, and
easy to maintain. Bestselling author Mohammed Kabir offers complete guidance on every detail of Apache
implementation, from installation and configuration to Web site administration, server-side applications, security,
and performance tuning. Whether you’re a novice Web administrator or an Apache veteran, this is the only book
you need to harness the power of the world’s leading Web server.
Shelving Category:
Networking/Internet
Reader Level:
Beginning to Advanced
System Requirements:
Pentium-class PC running Windows 9X/2000/Me
and XP; Linux; or Unix; CD-ROM drive.
See About the CD Appendix for details.
ISBN 0-7645-4821-2
$49.99 USA
$74.99 Canada
£39.99 UK incl. VAT
Apache Server 2
Configure Apache
Server for a
Linux/Unix or
Win32 system
Leverage Apache
using SSI, CGI, PHP,
Perl, and Java
servlets
Secure your site
using SSL, certificate-


signing services,
and other tools
A
pache Server 2
Mohammed J. Kabir
“Kabir has done it again! The Apache Server 2 Bible
is an invaluable reference for both beginning
and experienced administrators.”
— Elizabeth Zinkann, Sys Admin Magazine Contributing Editor and Review Columnist
,!7IA7G4-feicbf!:p;o;t;T;T
Apache, PHP,
Perl, and more
on CD-ROM!
BONUS
CD-ROM!
Apache, PHP, Perl,
Tomcat, MySQL, and more
www.hungryminds.com
100%
ONE HUNDRED PERCENT
COMPREHENSIVE
AUTHORITATIVE
WHAT YOU NEED
ONE HUNDRED PERCENT
CD-ROM features:
• Apache Web Server
• PHP, Perl, mod_ perl, MySQL, and other
open source tools for dynamic Web pages
• OpenSSL and ApacheSSL security software
• Plus all sample code from the book and more

A
pache Server 2
Bible
Author of Red Hat Linux Server
*85555-AHHDHj
100%
COMPREHENSIVE
Apache Server 2
Inside, You’ll Find Complete Coverage of Apache Server 2
• Master source compilation and binary installation
• Customize Apache to match your system
• Create and manage virtual Web sites with Apache
• Monitor server performance with a log analyzer package
• Set up an Apache-based proxy server
• Create a Web cycle involving development, testing, and production systems
• Turbocharge Web interactivity with FastCGI, PHP, Perl, and Java servlets
• Secure Apache with Apache SSL and your own Certificate Authority
• Configure Apache for Win32 systems
• Create a high-availability Web network using Apache
Create an interactive
Web site using JSP
servelets, CGI, and
mod_perl scripts
Request Load Balancer
Load Balancer
Switch
Front-end Network
207.183.233.17 207.183.233.17
www.[1-N].domain.com
Load Balancer

Web Server Farm
Switch
Application Server Farm Database Server Farm
192.168.1.1
Load Balancer
Back-end Network
192.168 .1.1
Configure your Web servers
for reliability and security
4821-2 cover 2/6/02 9:20 AM Page 1
Apache Server 2
Bible
a4821-2 FM.F 2/22/02 10:09 AM Page i
a4821-2 FM.F 2/22/02 10:09 AM Page ii
Apache Server 2
Bible
Mohammed J. Kabir
Best-Selling Books • Digital Downloads • e-Books • Answer Networks • e-Newsletters • Branded Web Sites • e-Learning
New York, NY✦ Cleveland, OH ✦ Indianapolis, IN
a4821-2 FM.F 2/22/02 10:09 AM Page iii
LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND AUTHOR HAVE USED THEIR BEST EFFORTS
IN PREPARING THIS BOOK. THE PUBLISHER AND AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH
RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS BOOK AND SPECIFICALLY DISCLAIM
ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. THERE ARE NO
WARRANTIES WHICH EXTEND BEYOND THE DESCRIPTIONS CONTAINED IN THIS PARAGRAPH. NO WARRANTY
MAY BE CREATED OR EXTENDED BY SALES REPRESENTATIVES OR WRITTEN SALES MATERIALS. THE ACCURACY
AND COMPLETENESS OF THE INFORMATION PROVIDED HEREIN AND THE OPINIONS STATED HEREIN ARE NOT
GUARANTEED OR WARRANTED TO PRODUCE ANY PARTICULAR RESULTS, AND THE ADVICE AND STRATEGIES
CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY INDIVIDUAL. NEITHER THE PUBLISHER NOR AUTHOR
SHALL BE LIABLE FOR ANY LOSS OF PROFIT OR ANY OTHER COMMERCIAL DAMAGES, INCLUDING BUT NOT

LIMITED TO SPECIAL, INCIDENTAL, CONSEQUENTIAL, OR OTHER DAMAGES.
Apache Server 2 Bible
Published by
Hungry Minds, Inc.
909 Third Avenue
New York, NY 10022
www.hungryminds.com
Copyright © 2002 Hungry Minds, Inc. All rights reserved. No part of this book, including interior design, cover design, and
icons, may be reproduced or transmitted in any form, by any means (electronic, photocopying, recording, or otherwise)
without the prior written permission of the publisher.
Library of Congress Control Number: 2001092889
ISBN: 0-7645-4821-2
Printed in the United States of America
10 9 8 7 6 5 4 3 2 1
1B/RT/QT/QS/IN
Distributed in the United States by Hungry Minds, Inc.
Distributed by CDG Books Canada Inc. for Canada; by Transworld Publishers Limited in the United Kingdom; by IDG Norge
Books for Norway; by IDG Sweden Books for Sweden; by IDG Books Australia Publishing Corporation Pty. Ltd. for Australia
and New Zealand; by TransQuest Publishers Pte Ltd. for Singapore, Malaysia, Thailand, Indonesia, and Hong Kong; by
Gotop Information Inc. for Taiwan; by ICG Muse, Inc. for Japan; by Intersoft for South Africa; by Eyrolles for France; by
International Thomson Publishing for Germany, Austria, and Switzerland; by Distribuidora Cuspide for Argentina; by LR
International for Brazil; by Galileo Libros for Chile; by Ediciones ZETA S.C.R. Ltda. for Peru; by WS Computer Publishing
Corporation, Inc., for the Philippines; by Contemporanea de Ediciones for Venezuela; by Express Computer Distributors for
the Caribbean and West Indies; by Micronesia Media Distributor, Inc. for Micronesia; by Chips Computadoras S.A. de C.V.
for Mexico; by Editorial Norma de Panama S.A. for Panama; by American Bookshops for Finland.
For general information on Hungry Minds’ products and services please contact our Customer Care department within the
U.S. at 800-762-2974, outside the U.S. at 317-572-3993 or fax 317-572-4002.
For sales inquiries and reseller information, including discounts, premium and bulk quantity sales, and foreign-language
translations, please contact our Customer Care department at 800-434-3422, fax 317-572-4002 or write to Hungry Minds,
Inc., Attn: Customer Care Department, 10475 Crosspoint Boulevard, Indianapolis, IN 46256.

For information on licensing foreign or domestic rights, please contact our Sub-Rights Customer Care department at
212-884-5000.
For information on using Hungry Minds’ products and services in the classroom or for ordering examination copies, please
contact our Educational Sales department at 800-434-2086 or fax 317-572-4005.
For press review copies, author interviews, or other publicity information, please contact our Public Relations department
at 317-572-3168 or fax 317-572-4168.
For authorization to photocopy items for corporate, personal, or educational use, please contact Copyright Clearance
Center, 222 Rosewood Drive, Danvers, MA 01923, or fax 978-750-4470.
Trademarks: Bible and Hungry Minds are trademarks or registered trademarks of Hungry Minds, Inc. All other trademarks
are the property of their respective owners. Hungry Minds, Inc., is not associated with any product or vendor mentioned in
this book.
is a trademark of Hungry Minds, Inc.
a4821-2 FM.F 2/22/02 10:09 AM Page iv
Credits
Acquisitions Editor
Terri Varveris
Project Editor
James H. Russell
Technical Editor
Gregory W. Stephens
Copy Editor
Richard H. Adin
Editorial Managers
Kyle Looper
Ami Frank Sullivan
Vice President & Executive
Group Publisher
Richard Swadley
Vice President & Group Publisher
Bob Ipsen

Editorial Director
Mary Bednarek
Project Coordinator
Regina Snyder
Graphics and Production Specialists
Beth Brooks
Melanie DesJardins
Joyce Haughey
Betty Schulte
Jeremey Unger
Quality Control Technicians
Laura Albert
John Greenough
Andy Hollandbeck
Angel Perez
Media Development Specialist
Travis Silvers
Illustrator
Kate Shaw
Proofreading and Indexing
TECHBOOKS Production Services
Cover Image
Kate Shaw
a4821-2 FM.F 2/22/02 10:09 AM Page v
About the Author
Mohammed Kabir is the founder and CEO of Evoknow, Inc. His company specializes
in CRM software development. When he is not busy managing software projects or
writing books, he enjoys traveling. Kabir studied computer engineering at California
State University, Sacramento. He can be reached at
a4821-2 FM.F 2/22/02 10:09 AM Page vi

To the memory of my mother, Nazma Bathen.
a4821-2 FM.F 2/22/02 10:09 AM Page vii
a4821-2 FM.F 2/22/02 10:09 AM Page viii
Preface
W
elcome to Apache Server 2.0. Chances are that you already have heard
about Apache server. In fact, more than 60 percent of all Web administra-
tors use Apache. Apache is the most powerful, open-source, Web-server platform in
the world.
As a practicing Web developer, researcher, and administrator, I find Apache to be
the perfect fit for most Web sites. Apache 2.0 is a major revision of Apache server.
Apache Group originally created a highly configurable Web server in the first ver-
sion, which became popular very fast; in version 2, Apache Group focused on scala-
bility, reliability, and performance. Major code revisions were done to create a very
scalable Apache architecture.
Today, Apache stands tall as the most widely used Web platform. Every day an
increasing number of corporations accept this open-source marvel into their IT
infrastructure. Many large IT companies, such as IBM, have embraced Apache in
their product offerings. The future of Apache looks great. Whether you’re new to
Apache or are already a practicing Apache administrator, now is the perfect time to
get started with Apache 2.0. This book will help you do just that.
How This Book Is Organized
The book has six parts. Very short descriptions of each part follow.
Part I: Getting Started
With a brief introduction to the world’s number one Web server, in this part I guide
you through the process of obtaining and compiling Apache. I show you how to get
Apache up and running with minimal changes to the default configuration files so
that you can get Apache up and running on your system as quickly as possible. This
part ends with complete references to the Apache core directives and standard
modules so that you can get ready for serious Apache administration tasks.

a4821-2 FM.F 2/22/02 10:09 AM Page ix
x
Apache Server 2 Bible
Part II: Web Site Administration
This part focuses on typical Web administration tasks such as virtual Web-site cre-
ation, user authentication and authorization tasks, monitoring, logging, rewriting
and redirecting URLs, proxy service, and the like. You learn a great deal there is to
know about creating and managing virtual Web sites. You master various methods
of user authentication, authorization, and access control techniques. You learn to
monitor Web servers and to customize log files for analysis.
Part III: Running Web Applications
This part focuses on the ways in which you can serve dynamic contents using
Apache. It covers Common Gateway Interface (CGI), Server-Side Includes (SSI),
FastCGI, PHP, mod_perl, and Java servlets. You quickly learn to use these technolo-
gies with Apache.
Part IV: Securing Your Web Site
Any computer on the Internet is subject to abuse or attempts of misuse. It is always
a good idea to play it safe and to take precautionary measures. In this part, you
learn to make your Web sites more secure and resistant to hacker attacks. You are
also introduced to the potential risks of running SSI and CGI programs and how to
take preventive measures to avoid these risks. You also learn to enable Secure
Socket Layer (SSL) service using Apache modules to enable secure e-commerce.
Part V: Running Apache on Windows
Apache on Windows (Win32) platform has become very popular; more and more
people are trying Apache on Windows platform. With Apache 2.0, the performance
of Apache Web server under this platform has become very promising. In this part,
you learn how to install and configure Apache on Win32 platform.
Part VI: Tuning for Performance and Scalability
In this part, I discuss how you can speed up Apache by tuning your Web server sys-
tem and by optimizing various Apache server configuration. The chapter provides a

great deal of information on how to benefit from high-performance hardware, how
to tune hard disks and file systems under Linux to enhance system performance. It
also covers Web caching and tuning issues related to Perl-based Web applications.
a4821-2 FM.F 2/22/02 10:09 AM Page x
xi
Preface
Conventions Used in This Book
You don’t have to learn any new conventions to read this book. Just remember that
when you are asked to enter a command, you need press the Enter or the Return
key after you type the command at your command prompt. A
monospaced font is
used to denote configuration or code segment.
Also, pay attention to these icons:
The Note icon indicates that something needs a bit more explanation.
The Tip icon tells you something that is likely to save you some time and effort.
The Caution icon makes you aware of a potential danger.
The On The CD-ROM icon clues you in to files, programs, and other goodies that
are on the CD-ROM.
The Cross=Reference icon helps you navigate the book better, pointing you to top-
ics that are related to the one you’re currently reading about.
Tell Us What You Think of This Book
Both Hungry Minds and I want to know what you think of this book. Please register
this book online at the Hungry Minds Web site (
www.hungryminds.com) and give
us your feedback. If you are interested in communicating with me directly, send
e-mail messages to
I will do my best to respond promptly.
The Book Web Site
This book has a Web site at You can visit
this Web site for updated contents, errata, and FAQ.

Cross-
Reference
On the
CD-ROM
Caution
Tip
Note
a4821-2 FM.F 2/22/02 10:09 AM Page xi
a4821-2 FM.F 2/22/02 10:09 AM Page xii
Acknowledgments
I
would like to thank the Apache Group for creating the most powerful, extensible,
and modular Web server in the world. I give special thanks to Ralf S. Engelschall.
Ralf, the author of the
mod_rewrite module, provided a great deal of support in the
development of Chapter 9 on URL rewriting rules. The practical examples in that
chapter are derived from his personal collection, which keeps growing at his Web
site
www.engelschall.com/pw/apache/rewriteguide.
I also thank the Hungry Minds team, who made this book a reality. It is impossible
to list everyone involved but I must mention the following kind individuals:
James Russell, the project development editor, kept this project going. I don’t know
how I could have done this book without his generous help and suggestions every
step of the way. Thanks James.
Terri Varveris, the acquisitions editor, provided me with this book opportunity and
made sure I saw it through to the end. Thanks, Terri.
Sheila Kabir, my wife, had to put up with many long work hours during the few
months it took to write this book. Thank you, sweetheart.
a4821-2 FM.F 2/22/02 10:09 AM Page xiii
Contents at a Glance

Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
Part I: Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Chapter 1: Apache: The Number One Web Server . . . . . . . . . . . . . . . . . . . 3
Chapter 2: Obtaining and Installing Apache . . . . . . . . . . . . . . . . . . . . . . 13
Chapter 3: Getting Apache Up and Running . . . . . . . . . . . . . . . . . . . . . . 31
Chapter 4: Configuring Apache with Winnt MPM directives . . . . . . . . . . . . . 55
Chapter 5: Apache Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Part II: Web Site Administration . . . . . . . . . . . . . . . . . . . . . 157
Chapter 6: Hosting Virtual Web Sites . . . . . . . . . . . . . . . . . . . . . . . . . 159
Chapter 7: Authenticating and Authorizing Web Site Visitors . . . . . . . . . . . 181
Chapter 8: Monitoring Access to Apache . . . . . . . . . . . . . . . . . . . . . . . 213
Chapter 9: Rewriting Your URLs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Chapter 10: Setting up a Proxy Server . . . . . . . . . . . . . . . . . . . . . . . . 265
Chapter 11: Running Perfect Web Sites . . . . . . . . . . . . . . . . . . . . . . . . 293
Part III: Running Web Applications . . . . . . . . . . . . . . . . . . . . 319
Chapter 12: Running CGI Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
Chapter 13: Server Side Includes (SSI) . . . . . . . . . . . . . . . . . . . . . . . . 377
Chapter 14: Configuring Apache for FastCGI . . . . . . . . . . . . . . . . . . . . . 399
Chapter 15: PHP and Apache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421
Chapter 16: Using Perl with Apache . . . . . . . . . . . . . . . . . . . . . . . . . . 455
Chapter 17: Running Java Servlets and JSP Pages with Tomcat . . . . . . . . . . 469
Part IV: Securing Your Web Site . . . . . . . . . . . . . . . . . . . . . . 493
Chapter 18: Web Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495
Chapter 19: Securing Apache with SSL . . . . . . . . . . . . . . . . . . . . . . . . 543
a4821-2 FM.F 2/22/02 10:09 AM Page xiv
Part V: Running Apache on Windows . . . . . . . . . . . . . . . . . . 567
Chapter 20: Installing and Running Apache for Windows . . . . . . . . . . . . . 569
Chapter 21: Configuring Apache for Windows . . . . . . . . . . . . . . . . . . . . 579
Part VI: Tuning for Performance and Scalability . . . . . . . . . . . . 591

Chapter 22: Speeding Up Apache . . . . . . . . . . . . . . . . . . . . . . . . . . . 593
Chapter 23: Creating a High-Availability Network . . . . . . . . . . . . . . . . . . 637
Appendix A: HTTP 1.1 Status Codes . . . . . . . . . . . . . . . . . . . . . . . . . . 705
Appendix B: Understanding Regular Expressions . . . . . . . . . . . . . . . . . . 709
Appendix C: Online Apache Resources . . . . . . . . . . . . . . . . . . . . . . . . 713
Appendix D: What’s on the CD-ROM? . . . . . . . . . . . . . . . . . . . . . . . . . 719
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 723
End-User License Agreement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 755
a4821-2 FM.F 2/22/02 10:09 AM Page xv
a4821-2 FM.F 2/22/02 10:09 AM Page xvi
Contents
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
Part I: Getting Started 1
Chapter 1: Apache: The Number One Web Server . . . . . . . . . . . . 3
Apache Rocks On . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Apache: The Beginning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
The Apache Feature List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Understanding Apache 2.0 Architecture . . . . . . . . . . . . . . . . . . . . . 7
Multiprocessing modules . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Filtering I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
New CGI daemon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Apache Portable Run-Time . . . . . . . . . . . . . . . . . . . . . . . . . 10
Understanding the Apache License . . . . . . . . . . . . . . . . . . . . . . . 10
Chapter 2: Obtaining and Installing Apache . . . . . . . . . . . . . . . 13
The Official Source for Apache . . . . . . . . . . . . . . . . . . . . . . . . . . 13
System Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Requirements for building Apache
from source distribution . . . . . . . . . . . . . . . . . . . . . . . . 14
Requirements for running an Apache Web server . . . . . . . . . . . . 16

Downloading the Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Installing Apache from Source Code . . . . . . . . . . . . . . . . . . . . . . . 19
Configuring Apache source . . . . . . . . . . . . . . . . . . . . . . . . . 19
Advanced configuration options for
high-load Web sites . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Compiling and installing Apache . . . . . . . . . . . . . . . . . . . . . 26
Installing Apache from RPM Binary Packages . . . . . . . . . . . . . . . . . 30
Keeping Up with Apache Development . . . . . . . . . . . . . . . . . . . . . 30
Chapter 3: Getting Apache Up and Running . . . . . . . . . . . . . . . 31
Configuring Apache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Configuring the global environment for Apache . . . . . . . . . . . . . 36
Configuring the main server . . . . . . . . . . . . . . . . . . . . . . . . 40
Starting and Stopping Apache . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Starting Apache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Restarting Apache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Stopping Apache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Testing Apache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
a4821-2 FM.F 2/22/02 10:09 AM Page xvii
xviii
Apache Server 2 Bible
Chapter 4: Configuring Apache with Winnt MPM
Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Apache Directive Contexts . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Server config context . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Container context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Per-directory context . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
General Configuration Directives . . . . . . . . . . . . . . . . . . . . . . . . . 59
AccessFileName . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
AddDefaultCharset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
ContentDigest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

DefaultType . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
DocumentRoot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
ErrorDocument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
<IfDefine> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
<IfModule> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Include . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Port . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
ServerAdmin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
ServerName . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
ServerRoot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
ServerSignature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
ServerTokens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
SetInputFilter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
SetOutputFilter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Performance and Resource
Configuration Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Controlling Apache processes . . . . . . . . . . . . . . . . . . . . . . . 71
Making persistent connections . . . . . . . . . . . . . . . . . . . . . . 72
Controlling system resources . . . . . . . . . . . . . . . . . . . . . . . 74
Using dynamic modules . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Standard Container Directives . . . . . . . . . . . . . . . . . . . . . . . . . . 76
<Directory> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
<DirectoryMatch> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
<Files> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
<FilesMatch> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
<Location> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
<LocationMatch> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Virtual Host-Specific Directives . . . . . . . . . . . . . . . . . . . . . . . . . . 80
NameVirtualHost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80

ServerAlias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
ServerPath . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
<VirtualHost> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Logging Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
LogLevel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
PidFile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
ScoreBoardFile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
a4821-2 FM.F 2/22/02 10:09 AM Page xviii
xix
Contents
Authentication and Security Directives . . . . . . . . . . . . . . . . . . . . . 86
AllowOverride . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
AuthName . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
AuthType . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
HostNameLookups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
IdentityCheck . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
<Limit> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
<LimitExcept> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
LimitRequestBody . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
LimitRequestFields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
LimitRequestFieldsize . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
LimitRequestLine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Require . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Satisfy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
ScriptInterpreterSource . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
MPM threaded-Specific Directives . . . . . . . . . . . . . . . . . . . . . . . . 92
CoreDumpDirectory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Group . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Listen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
ListenBacklog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94

LockFile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
MaxClients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
MaxRequestsPerChild . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
MaxSpareThreads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
MinSpareThreads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
SendBufferSize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
StartServers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
ThreadsPerChild . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
MPM perchild-Specific Directives . . . . . . . . . . . . . . . . . . . . . . . . 98
AssignUserID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
ChildPerUserID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
ConnectionStatus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
CoreDumpDirectory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Group . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Listen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
ListenBacklog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
LockFile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
MaxRequestsPerChild . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
MaxSpareThreads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
MaxThreadsPerChild . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
MinSpareThreads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
NumServers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
PidFile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
ScoreBoardFile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
SendBufferSize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
StartThreads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
a4821-2 FM.F 2/22/02 10:09 AM Page xix
xx

Apache Server 2 Bible
MPM winnt-Specific Directives . . . . . . . . . . . . . . . . . . . . . . . . . 101
CoreDumpDirectory . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Listen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
ListenBacklog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
MaxRequestsPerChild . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
PidFile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
SendBufferSize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
ThreadsPerChild . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
MPM prefork Specific Directives . . . . . . . . . . . . . . . . . . . . . . . . 102
CoreDumpDirectory . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Group . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Listen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
ListenBacklog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
LockFile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
MaxClients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
MaxRequestsPerChild . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
MaxSpareServers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
MinSpareServers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
PidFile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
ScoreBoardFile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
SendBufferSize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
StartServers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Chapter 5: Apache Modules . . . . . . . . . . . . . . . . . . . . . . . . 105
An Overview of the Modules . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Environment-Related Modules . . . . . . . . . . . . . . . . . . . . . . . . . 106
mod_env . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
mod_setenvif . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
mod_unique_id . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109

Authentication and Access Control Modules . . . . . . . . . . . . . . . . . 109
mod_auth_anon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
mod_auth_dbm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
mod_auth_db . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Dynamic Contents Generation Modules . . . . . . . . . . . . . . . . . . . . 117
mod_actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
mod_ext_filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Content-Type Configuration Modules . . . . . . . . . . . . . . . . . . . . . 124
mod_mime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
mod_mime_magic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
mod_negotiation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Directory Listing Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
mod_dir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
mod_autoindex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Response Header Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
mod_asis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
mod_headers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
a4821-2 FM.F 2/22/02 10:09 AM Page xx
xxi
Contents
mod_expires . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
mod_cern_meta . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
Server Information and Logging Modules . . . . . . . . . . . . . . . . . . . 143
mod_log_config . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
mod_status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
mod_info . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
mod_usertrack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
URL Mapping Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
mod_userdir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
mod_alias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145

mod_speling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
mod_vhost_alias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Miscellaneous Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
mod_so . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
mod_imap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
mod_file_cache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
mod_dav . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Part II: Web Site Administration 157
Chapter 6: Hosting Virtual Web Sites . . . . . . . . . . . . . . . . . . 159
Understanding Apache’s Virtual Hosting Capabilities . . . . . . . . . . . . 159
Setting Up a Virtual Host . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
Name-based virtual hosts . . . . . . . . . . . . . . . . . . . . . . . . . 161
IP-based virtual hosts . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Multiple main servers as virtual hosts . . . . . . . . . . . . . . . . . 163
Configuring DNS for a Virtual Host . . . . . . . . . . . . . . . . . . . . . . . 166
Setting User and Group per Virtual Host . . . . . . . . . . . . . . . . . . . . 169
Managing a Large Number of Virtual Hosts . . . . . . . . . . . . . . . . . . 170
Automating Virtual Host Configuration using mod_perl . . . . . . . . . . . 171
Generating Virtual Host Configuration By Using the makesite Script . . . 175
Managing Virtual Hosts By Using MySQL with mod_v2h Module . . . . . . 178
Chapter 7: Authenticating and Authorizing Web Site Visitors . . . . 181
Authentication vs. Authorization . . . . . . . . . . . . . . . . . . . . . . . . 181
Understanding How Authentication Works . . . . . . . . . . . . . . . . . . 182
Authenticating Users Via the mod_auth Module . . . . . . . . . . . . . . . 184
Understanding the mod_auth directives . . . . . . . . . . . . . . . . 184
Creating a members-only section in your Web site . . . . . . . . . . 186
Creating a members-only section using a .htaccess file . . . . . . . . 187
Grouping users for restricted access to different Web sections . . . 188
Authorizing Access via Host Name or IP Addresses . . . . . . . . . . . . . 190
allow directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190

deny directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
order directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
Combining Authentication and Authorization . . . . . . . . . . . . . . . . 195
a4821-2 FM.F 2/22/02 10:09 AM Page xxi
xxii
Apache Server 2 Bible
Authenticating with a Relational Database . . . . . . . . . . . . . . . . . . 195
Using MySQL database server for authentication . . . . . . . . . . . 196
Using other databases for user authentication . . . . . . . . . . . . . 202
Managing Users and Groups in Any RDBM . . . . . . . . . . . . . . . . . . 204
Secure Authenticated Sessions Using Cookies . . . . . . . . . . . . . . . . 208
Chapter 8: Monitoring Access to Apache . . . . . . . . . . . . . . . . 213
Monitoring Apache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
Accessing configuration information with mod_info . . . . . . . . . 214
Enabling status pages with mod_status . . . . . . . . . . . . . . . . . 216
Creating Log Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
TransferLog directive . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
LogFormat directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
CustomLog directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
CookieLog directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
Customizing Your Log Files . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
Creating Multiple Log Files . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
Logging Cookies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
Using Error Logs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
Analyzing Your Log Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
Log Maintenance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
Using rotatelog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
Using logrotate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
Using logresolve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
Chapter 9: Rewriting Your URLs . . . . . . . . . . . . . . . . . . . . . . 239

The URL-Rewriting Engine for Apache . . . . . . . . . . . . . . . . . . . . . 239
RewriteEngine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
RewriteOptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
RewriteRule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
RewriteCond . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
RewriteMap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
RewriteBase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
RewriteLog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
RewriteLogLevel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
RewriteLock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
URL Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
Expanding a requested URL to a canonical URL . . . . . . . . . . . . 251
Redirecting a user home directory to a new Web server . . . . . . . 252
Searching for a page in multiple directories . . . . . . . . . . . . . . 253
Setting an environment variable based on a URL . . . . . . . . . . . 256
Creating www.username.domain.com sites . . . . . . . . . . . . . . . 257
Redirecting a failing URL to another Web server . . . . . . . . . . . . 259
Creating an access multiplexer . . . . . . . . . . . . . . . . . . . . . . 259
Creating time-sensitive URLs . . . . . . . . . . . . . . . . . . . . . . . 261
a4821-2 FM.F 2/22/02 10:09 AM Page xxii
xxiii
Contents
Content Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
Adding backward compatibility in URLs . . . . . . . . . . . . . . . . 262
Creating browser-matched content URLs . . . . . . . . . . . . . . . . 262
Creating an HTML to CGI gateway . . . . . . . . . . . . . . . . . . . . 263
Access Restriction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
Blocking robots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
Creating an HTTP referer-based URL deflector . . . . . . . . . . . . . 264
Chapter 10: Setting up a Proxy Server . . . . . . . . . . . . . . . . . . 265

Who Should Use a Proxy Server? . . . . . . . . . . . . . . . . . . . . . . . . 265
Understanding Types of Proxy Servers . . . . . . . . . . . . . . . . . . . . 266
Forward proxy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
Reverse proxy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
mod_proxy Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
ProxyRequests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
ProxyRemote . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
ProxyPass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
ProxyBlock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
NoProxy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
ProxyDomain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
CacheRoot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
CacheSize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
CacheGcInterval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
CacheMaxExpire . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
CacheLastModifiedFactor . . . . . . . . . . . . . . . . . . . . . . . . . 273
CacheDirLength . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
CacheDirLevels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
CacheDefaultExpire . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
NoCache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
Configuring an Apache Proxy Server . . . . . . . . . . . . . . . . . . . . . . 275
Scenario 1: Connecting a private IP network to the Internet . . . . . 276
Scenario 2: Caching remote Web sites . . . . . . . . . . . . . . . . . . 276
Scenario 3: Mirroring a Web site . . . . . . . . . . . . . . . . . . . . . 278
Setting Up Web Browsers to use a Proxy . . . . . . . . . . . . . . . . . . . 278
Manual proxy configuration . . . . . . . . . . . . . . . . . . . . . . . 278
Automatic proxy configuration . . . . . . . . . . . . . . . . . . . . . . 281
Setting return values for FindProxyForURL . . . . . . . . . . . . . . . 282
Using pre-defined functions in FindProxyForURL . . . . . . . . . . . 283
Chapter 11: Running Perfect Web Sites . . . . . . . . . . . . . . . . . 293

What is a Web Development Cycle? . . . . . . . . . . . . . . . . . . . . . . 294
Putting the Web Cycle into Action . . . . . . . . . . . . . . . . . . . . . . . 296
Setting up for the Web cycle . . . . . . . . . . . . . . . . . . . . . . . 297
Implementing the Web cycle . . . . . . . . . . . . . . . . . . . . . . . 301
Building a Web Site by Using Templates and makepage . . . . . . . . . . . 304
a4821-2 FM.F 2/22/02 10:09 AM Page xxiii
xxiv
Apache Server 2 Bible
Using HTTP PUT for Intranet Web Publishing . . . . . . . . . . . . . . . . . 305
Understanding the directives in mod_put module . . . . . . . . . . . 306
Compiling and installing mod_put . . . . . . . . . . . . . . . . . . . . 307
Setting up a PUT-enabled Web directory . . . . . . . . . . . . . . . . 307
Setting up a virtual host to use mod_put module . . . . . . . . . . . 309
Maintaining Your Web Site . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
Online backup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
Offline backup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
Standardizing Standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
HTML document development policy . . . . . . . . . . . . . . . . . . 312
Dynamic application development policy . . . . . . . . . . . . . . . . 314
Giving Your Web Site a User-Friendly Interface . . . . . . . . . . . . . . . . 315
Make your site easy to navigate . . . . . . . . . . . . . . . . . . . . . 316
Create an appealing design . . . . . . . . . . . . . . . . . . . . . . . . 316
Remove cryptic error messages . . . . . . . . . . . . . . . . . . . . . 317
Test your Web GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
Promoting Your Web Site . . . . . . . . . . . . . . . . . . . . . . . . . 318
Part III: Running Web Applications 319
Chapter 12: Running CGI Scripts . . . . . . . . . . . . . . . . . . . . . 321
What Is CGI? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
CGI Input and Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
GET requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323

POST requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
Comparing GET and POST . . . . . . . . . . . . . . . . . . . . . . . . 327
Decoding input data . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
Apache CGI Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
Server variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
Client request variables . . . . . . . . . . . . . . . . . . . . . . . . . . 330
Configuring Apache for CGI . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
Aliasing your CGI program directory . . . . . . . . . . . . . . . . . . 335
Choosing specific CGI file extensions . . . . . . . . . . . . . . . . . . 336
Enabling cgi-bin access for your users . . . . . . . . . . . . . . . . . 338
Creating new CGI extensions by using AddType . . . . . . . . . . . . 341
Running CGI Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
Writing CGI Scripts in Perl . . . . . . . . . . . . . . . . . . . . . . . . . 342
Enabling CGI Debugging Support in Apache . . . . . . . . . . . . . . . . . . 370
ScriptLog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370
ScriptLogLength . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
ScriptLogBuffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
Debugging Your Perl-Based CGI Scripts . . . . . . . . . . . . . . . . . . . . 371
Debugging from the command line . . . . . . . . . . . . . . . . . . . 371
Debugging by using logging and debug printing . . . . . . . . . . . . 373
Debugging with CGI::Debug . . . . . . . . . . . . . . . . . . . . . . . . 374
a4821-2 FM.F 2/22/02 10:09 AM Page xxiv

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×