1. Trang chủ
  2. » Công Nghệ Thông Tin

Apache the definitive guide, 3rd edition

622 70 1

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 622
Dung lượng 2,31 MB

Nội dung

Copyright Preface Who Wrote Apache, and Why? The Demonstration Code Conventions Used in This Book Organization of This Book Acknowledgments Chapter Getting Started Section 1.1 What Does a Web Server Do? Section 1.2 How Apache Works Section 1.3 Apache and Networking Section 1.4 How HTTP Clients Work Section 1.5 What Happens at the Server End? Section 1.6 Planning the Apache Installation Section 1.7 Windows? Section 1.8 Which Apache? Section 1.9 Installing Apache Section 1.10 Building Apache 1.3.X Under Unix Section 1.11 New Features in Apache v2 Section 1.12 Making and Installing Apache v2 Under Unix Section 1.13 Apache Under Windows Chapter Configuring Apache: The First Steps Section 2.1 What's Behind an Apache Web Site? Section 2.2 site.toddle Section 2.3 Setting Up a Unix Server Section 2.4 Setting Up a Win32 Server Section 2.5 Directives Section 2.6 Shared Objects Chapter Toward a Real Web Site Section 3.1 More and Better Web Sites: site.simple Section 3.2 Butterthlies, Inc., Gets Going Section 3.3 Block Directives Section 3.4 Other Directives Section 3.5 HTTP Response Headers Section 3.6 Restarts Section 3.7 .htaccess Section 3.8 CERN Metafiles Section 3.9 Expirations Chapter Virtual Hosts Section 4.1 Two Sites and Apache Section 4.2 Virtual Hosts Section 4.3 Two Copies of Apache Section 4.4 Dynamically Configured Virtual Hosting Chapter Authentication Section 5.1 Authentication Protocol Section 5.2 Authentication Directives Section 5.3 Passwords Under Unix Section 5.4 Passwords Under Win32 Section 5.5 Passwords over the Web Section 5.6 From the Client's Point of View Section 5.7 CGI Scripts Section 5.8 Variations on a Theme Section 5.9 Order, Allow, and Deny Section 5.10 DBM Files on Unix Section 5.11 Digest Authentication Section 5.12 Anonymous Access Section 5.13 Experiments Section 5.14 Automatic User Information Section 5.15 Using htaccess Files Section 5.16 Overrides Chapter Content Description and Modification Section 6.1 MIME Types Section 6.2 Content Negotiation Section 6.3 Language Negotiation Section 6.4 Type Maps Section 6.5 Browsers and HTTP 1.1 Section 6.6 Filters Chapter Indexing Section 7.1 Making Better Indexes in Apache Section 7.2 Making Our Own Indexes Section 7.3 Imagemaps Section 7.4 Image Map Directives Chapter Redirection Section 8.1 Alias Section 8.2 Rewrite Section 8.3 Speling Chapter Proxying Section 9.1 Security Section 9.2 Proxy Directives Section 9.3 Apparent Bug Section 9.4 Performance Section 9.5 Setup Chapter 10 Logging Section 10.1 Logging by Script and Database Section 10.2 Apache's Logging Facilities Section 10.3 Configuration Logging Section 10.4 Status Chapter 11 Security Section 11.1 Internal and External Users Section 11.2 Binary Signatures, Virtual Cash Section 11.3 Certificates Section 11.4 Firewalls Section 11.5 Legal Issues Section 11.6 Secure Sockets Layer (SSL) Section 11.7 Apache's Security Precautions Section 11.8 SSL Directives Section 11.9 Cipher Suites Section 11.10 Security in Real Life Section 11.11 Future Directions Chapter 12 Running a Big Web Site Section 12.1 Machine Setup Section 12.2 Server Security Section 12.3 Managing a Big Site Section 12.4 Supporting Software Section 12.5 Scalability Section 12.6 Load Balancing Chapter 13 Building Applications Section 13.1 Web Sites as Applications Section 13.2 Providing Application Logic Section 13.3 XML, XSLT, and Web Applications Chapter 14 Server-Side Includes Section 14.1 File Size Section 14.2 File Modification Time Section 14.3 Includes Section 14.4 Execute CGI Section 14.5 Echo Section 14.6 Apache v2: SSI Filters Chapter 15 PHP Section 15.1 Installing PHP Section 15.2 Site.php Chapter 16 CGI and Perl Section 16.1 Section 16.2 Section 16.3 Section 16.4 Section 16.5 Section 16.6 Section 16.7 Section 16.8 Section 16.9 The World of CGI Telling Apache About the Script Setting Environment Variables Cookies Script Directives suEXEC on Unix Handlers Actions Browsers Chapter 17 mod_perl Section 17.1 How mod_perl Works Section 17.2 mod_perl Documentation Section 17.3 Installing mod_perl — The Simple Way Section 17.4 Modifying Your Scripts to Run Under mod_perl Section 17.5 Global Variables Section 17.6 Strict Pregame Section 17.7 Loading Changes Section 17.8 Opening and Closing Files Section 17.9 Configuring Apache to Use mod_perl Chapter 18 mod_jserv and Tomcat Section 18.1 mod_jserv Section 18.2 Tomcat Section 18.3 Connecting Tomcat to Apache Chapter 19 XML and Cocoon Section 19.1 XML Section 19.2 XML and Perl Section 19.3 Cocoon Section 19.4 Cocoon 1.8 and JServ Section 19.5 Cocoon 2.0.3 and Tomcat Section 19.6 Testing Cocoon Chapter 20 The Apache API Section 20.1 Documentation Section 20.2 APR Section 20.3 Pools Section 20.4 Per-Server Configuration Section 20.5 Per-Directory Configuration Section 20.6 Per-Request Information Section 20.7 Access to Configuration and Request Information Section 20.8 Hooks, Optional Hooks, and Optional Functions Section 20.9 Filters, Buckets, and Bucket Brigades Section 20.10 Modules Chapter 21 Writing Apache Modules Section 21.1 Overview Section 21.2 Status Codes Section 21.3 The Module Structure Section 21.4 A Complete Example Section 21.5 General Hints Section 21.6 Porting to Apache 2.0 Appendix A The Apache 1.x API Section A.1 Pools Section A.2 Per-Server Configuration Section A.3 Per-Directory Configuration Section A.4 Per-Request Information Section A.5 Access to Configuration and Request Information Section A.6 Functions Colophon Index Copyright Copyright © O'Reilly & Associates, Inc Printed in the United States of America Published by O'Reilly & Associates, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472 O'Reilly & Associates books may be purchased for educational, business, or sales promotional use Online editions are also available for most titles (http://safari.oreilly.com) For more information, contact our corporate/institutional sales department: (800) 998-9938 or corporate@oreilly.com Nutshell Handbook, the Nutshell Handbook logo, and the O'Reilly logo are registered trademarks of O'Reilly & Associates, Inc Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks Where those designations appear in this book, and O'Reilly & Associates, Inc was aware of a trademark claim, the designations have been printed in caps or initial caps The association between the image of Appaloosa horse and the topic of Apache is a trademark of O'Reilly & Associates, Inc While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein Preface Apache: The Definitive Guide, Third Edition, is principally about the Apache web-server software We explain what a web server is and how it works, but our assumption is that most of our readers have used the World Wide Web and understand in practical terms how it works, and that they are now thinking about running their own servers and sites This book takes the reader through the process of acquiring, compiling, installing, configuring, and modifying Apache We exercise most of the package's functions by showing a set of example sites that take a reasonably typical web business — in our case, a postcard publisher — through a process of development and increasing complexity However, we have deliberately tried to make each site as simple as possible, focusing on the particular feature being described Each site is pretty well self-contained, so that the reader can refer to it while following the text without having to disentangle the meat from extraneous vegetables If desired, it is possible to install and run each site on a suitable system Perhaps it is worth saying what this book is not It is not a manual, in the sense of formally documenting every command — such a manual exists on the Apache site and has been much improved with Versions 1.3 and 2.0; we assume that if you want to use Apache, you will download it and keep it at hand Rather, if the manual is a road map that tells you how to get somewhere, this book tries to be a tourist guide that tells you why you might want to make the journey In passing, we reproduce some sections of the web site manual simply to save the reader the trouble of looking up the formal definitions as she follows the argument Occasionally, we found the manual text hard to follow and in those cases we have changed the wording slightly We have also interspersed comments as seemed useful at the time This is not a book about HTML or creating web pages, or one about web security or even about running a web site These are all complex subjects that should be either treated thoroughly or left alone As a result, a webmaster's library might include books on the following topics: • • • • • • The Web and how it works HTML — formal definitions, what you can with it How to decide what sort of web site you want, how to organize it, and how to protect it How to implement the site you want using one of the available servers (for instance, Apache) Handbooks on Java, Perl, and other languages Security Apache: The Definitive Guide is just one of the six or so possible titles in the fourth category Apache is a versatile package and is becoming more versatile every day, so we have not tried to illustrate every possible combination of commands; that would require a book of a million pages or so Rather, we have tried to suggest lines of development that a typical webmaster could follow once an understanding of the basic concepts is achieved We realized from our own experience that the hardest stage of learning how to use Apache in a real-life context is right at the beginning, where the novice webmaster often has to get Apache, a scripting language, and a database manager to collaborate This can be very puzzling In this new edition we have therefore included a good deal of new material which tries to take the reader up these conceptual precipices Once the collaboration is working, development is much easier These new chapters are not intended to be an experts' account of, say, the interaction between Apache, Perl, and MySQL — but a simple beginners' guide, explaining how to make these things work with Apache In the process we make some comments, from our own experience, on the merits of the various software products from which the user has to choose As with the first and second editions, writing the book was something of a race with Apache's developers We wanted to be ready as soon as Version was stable, but not before the developers had finished adding new features In many of the examples that follow, the motivation for what we make Apache is simple enough and requires little explanation (for example, the different index formats in Chapter 7) Elsewhere, we feel that the webmaster needs to be aware of wider issues (for instance, the security issues discussed in Chapter 11) before making sensible decisions about his site's configuration, and we have not hesitated to branch out to deal with them Who Wrote Apache, and Why? Apache gets its name from the fact that it consists of some existing code plus some patches The FAQFAQ is netspeak for Frequently Asked Questions Most sites/subjects have an FAQ file that tells you what the thing is, why it is, and where it's going It is perfectly reasonable for the newcomer to ask for the FAQ to look up anything new to her, and indeed this is a sensible thing to do, since it reduces the number of questions asked Apache's FAQ can be found at http://www.apache.org/docs/FAQ.html thinks that this is cute; others may think it's the sort of joke that gets programmers a bad name A more responsible group thinks that Apache is an appropriate title because of the resourcefulness and adaptability of the American Indian tribe You have to understand that Apache is free to its users and is written by a team of volunteers who not get paid for their work Whether they decide to incorporate your or anyone else's ideas is entirely up to them If you don't like what they do, feel free to collect a team and write your own web server or to adapt the existing Apache code — as many have The first web server was built by the British physicist Tim Berners-Lee at CERN, the European Centre for Nuclear Research at Geneva, Switzerland The immediate ancestor of Apache was built by the U.S government's NCSA, the National Center for Supercomputing Applications Because this code was written with (American) taxpayers' money, it is available to all; you can, if you like, download the source code in C from http://www.ncsa.uiuc.edu, paying due attention to the license conditions There were those who thought that things could be done better, and in the FAQ for Apache (at http://www.apache.org ), we read: Apache was originally based on code and ideas found in the most popular HTTP server of the time, NCSA httpd 1.3 (early 1995) That phrase "of the time" is nice It usually refers to good times back in the 1700s or the early days of technology in the 1900s But here it means back in the deliquescent bogs of a few years ago! While the Apache site is open to all, Apache is written by an invited group of (we hope) reasonably good programmers One of the authors of this book, Ben, is a member of this group Why they bother? Why these programmers, who presumably could be well paid for doing something else, sit up nights to work on Apache for our benefit? There is no such thing as a free lunch, so they it for a number of typically human reasons One might list, in no particular order: • • • • • They want to something more interesting than their day job, which might be writing stock control packages for BigBins, Inc They want to be involved on the edge of what is happening Working on a project like this is a pretty good way to keep up-to-date After that comes consultancy on the next hot project The more worldly ones might remember how, back in the old days of 1995, quite a lot of the people working on the web server at NCSA left for a thing called Netscape and became, in the passage of the age, zillionaires It's fun Developing good software is interesting and amusing, and you get to meet and work with other clever people They are not doing the bit that programmers hate: explaining to end users why their treasure isn't working and trying to fix it in 10 minutes flat If you want support on Apache, you have to consult one of several commercial organizations (see Appendix A), who, quite properly, want to be paid for doing the work everyone loathes The Demonstration Code The code for the demonstration web sites referred to throughout the book is available at http://www.oreilly.com/catalog/apache3/ It contains the requisite README file with installation instructions and other useful information The contents of the download are organized into two directories: install/ This directory contains scripts to install the sample sites: install Run this script to install the sites install.conf Unix configuration file for install installwin.conf Win32 configuration file for install sites/ This directory contains the sample sites used in the book Conventions Used in This Book This section covers the various conventions used in this book Typographic Conventions Constant width Used for HTTP headers, status codes, MIME content types, directives in configuration files, commands, options/switches, functions, methods, variable names, and code within body text Constant width bold Used in code segments to indicate input to be typed in by the user Constant width italic Used for replaceable items in code and text void ap_close_piped_log (piped_log *pl) Closes pl Doesn't kill the spawned child ap_piped_log_write_fd get the file descriptor of a log pipe int ap_piped_log_write_fd(piped_log *pl) Returns the file descriptor of an open piped log A.6.22 Buffering Functions Apache provides its own I/O buffering interface This allows chunked transfers to be done transparently and hides differences between files and sockets under Win32 ap_bcreate create a buffered stream BUFF *ap_bcreate(pool *p, int flags) Creates a new buffered stream in p The stream is not associated with any file or socket at this point flags are a combination of one of the following: B_RD Reading is buffered B_WR Writing is buffered B_RDWR Reading and writing are buffered B_SOCKET (optional) The stream will be buffering a socket Note that this flag also enables ASCII/EBCDIC translation on platforms that use EBCDIC (see ap_bsetflag( )) ap_bpushfd set the file descriptors for a stream void ap_bpushfd(BUFF *fb, int fd_in, int fd_out) Sets the read file descriptor to fd_in and the write file descriptor to fd_out Use -1 for file descriptors you don't want to set Note that these descriptors must be readable with read( ) and writable with write( ) ap_bpushh set a Win32 handle for a stream void ap_bpushh(BUFF *fb, HANDLE hFH) Sets a Win32 file handle for both input and output The handle will be written with WriteFile( ) and read with ReadFile( ) Note that this function should not be used for a socket, even though a socket is a Win32 handle ap_bpushfd( ) should be used for sockets ap_bsetopt set an option int ap_bsetopt(BUFF *fb, int optname, const void *optval) Sets the option optname to the value pointed at by optval There is currently only one option, which is the count of bytes sent to the stream,[5] set with BO_BYTECT In this case, optval should point to a long This function is used for logging and statistics and is not normally called by modules Its main use, when it is called, is to zero the count after sending headers to a client Returns on success or -1 on failure ap_bgetopt get the value of an option int ap_bgetopt(BUFF *fb, int optname, void *optval) Gets the value of the option optname in the location pointed at by optval The only supported option is BO_BYTECT (see ap_bsetopt( )) ap_bsetflag set or clear a flag int ap_bsetflag(BUFF *fb, int flag, int value) If value is 0, clear flag; otherwise, set it flag is one of the following: B_EOUT Prevent further I/O B_CHUNK Use chunked writing B_SAFEREAD Force an ap_bflush( ) if a read would block B_ASCII2EBCDIC Convert ASCII to EBCDIC when reading Only available on systems that support EBCDIC B_EBCDIC2ASCII Convert EBCDIC to ASCII when writing Only available on systems that support EBCDIC ap_bgetflag get a flag's setting int ap_bgetflag(BUFF *fb, int flag) Returns if flag is not set; nonzero otherwise See ap_bsetflag( ) for a list of flags ap_bonerror register an error function void ap_bonerror(BUFF *fb, void (*error) (BUFF *, int, void *),void *data) When an error occurs on fb, error( ) is called with fb, the direction (B_RD or B_WR), and data ap_bnonblock set a stream to nonblocking mode int ap_bnonblock(BUFF *fb, int direction) direction is one of B_RD or B_WR Sets the corresponding file descriptor to be nonblocking Returns whatever fcntl( ) returns ap_bfileno get a file descriptor from a stream int ap_bfileno(BUFF *fb, int direction) direction is one of B_RD or B_WR Returns the corresponding file descriptor ap_bread read from a stream int ap_bread(BUFF *fb, void *buf, int nbyte) Reads up to nbyte bytes into buf Returns the number of bytes read, on end of file (EOF), or -1 for an error Only reads the data currently available ap_bgetc get a character from a stream int ap_bgetc(BUFF *fb) Reads a single character from fb Returns the character on success and returns EOF on error or end of file If the EOF is the result of an end of file, errno will be zero ap_bgets read a line from a stream int ap_bgets(char *buff, int n, BUFF *fb) Reads up to n-1 bytes into buff until an LF is seen or the end of file is reached If LF is preceded by CR, the CR is deleted The buffer is then terminated with a NUL (leaving the LF as the character before the NUL) Returns the number of bytes stored in the buffer, excluding the terminating NUL ap_blookc peek at the next character in a stream int ap_blookc(char *buff, BUFF *fb) Places the next character in the stream in *buff, without removing it from the stream Returns on success, on EOF, and -1 on error ap_bskiplf discard until an LF is read int ap_bskiplf(BUFF *fb) Discards input until an LF is read Returns on success, on EOF, and -1 on an error The stream must be read-buffered (i.e., in B_RD or B_RDWR mode) ap_bwrite write to a stream int ap_bwrite(BUFF *fb, const void *buf, int nbyte) Writes nbyte bytes from buf to fb Returns the number of bytes written This can only be less than nbyte if an error occurred Takes care of chunked encoding if the B_CHUNK flag is set ap_bputc write a single character to a stream int ap_bputc(char c, BUFF *fb) Writes c to fb, returning on success or -1 on an error ap_bputs write a NUL-terminated string to a stream int ap_bputs(const char *buf, BUFF *fb) Writes the contents of buf up to, but not including, the first NUL Returns the number of bytes written or -1 on an error ap_bvputs write several NUL-terminated strings to a stream int ap_bvputs(BUFF *fb, ) Writes the contents of a list of buffers in the same manner as ap_bputs( ) The list of buffers is terminated with a NULL Returns the total number of bytes written or -1 on an error For example: if(ap_bvputs(fb,buf1,buf2,buf3,NULL) < 0) ap_bprintf write formatted output to a stream int ap_bprintf(BUFF *fb, const char *fmt, ) Write formatted output, as defined by fmt, to fb Returns the number of bytes sent to the stream ap_vbprintf write formatted output to a stream int ap_vbprintf(BUFF *fb, const char *fmt, va_list ap) Similar to ap_bprintf( ), except it uses a va_list instead of " " ap_bflush flush output buffers int ap_bflush(BUFF *fb) Flush fb's output buffers Returns on success and -1 on error Note that the file must be write-buffered (i.e., in B_WR or B_RDWR mode) ap_bclose close a stream int ap_bclose(BUFF *fb) Flushes the output buffer and closes the underlying file descriptors/handle/socket Returns on success and -1 on error A.6.23 URI Functions Some of these functions use the uri_components structure: typedef struct { char *scheme; char *hostinfo; char *user; */ char *password; */ char *hostname; char *port_str; "port") */ char *path; was /* scheme ("http"/"ftp"/ ) */ /* combined [user[:password]@]host[:port] */ /* username, as in http://user:passwd@host:port/ /* password, as in http://user:passwd@host:port/ /* hostname from URI (or from Host: header) */ /* port string (integer representation is in /* The request path (or "/" if only scheme://host /* given) */ char *query; /* Everything after a '?' in the path, if present */ char *fragment; /* Trailing "#fragment" string, if present */ struct hostent *hostent; unsigned short port; /* The port number, numeric, valid only if /* port_str != NULL */ unsigned is_initialized:1; unsigned dns_looked_up:1; unsigned dns_resolved:1; } uri_components; ap_parse_uri_components dissect a full URI int ap_parse_uri_components(pool *p, const char *uri, uri_components *uptr) Dissects the URI uri into its components, which are placed in uptr Each component is allocated in p Any missing components are set to NULL uptr->is_initialized is set to ap_parse_hostinfo_components dissect host:port int ap_parse_hostinfo_components(pool *p, const char *hostinfo, uri_components *uptr) Occasionally, it is necessary to parse host:port — for example, when handling a CONNECT request This function does that, setting uptr->hostname, uptr->port_str, and uptr->port (if the port component is present) All other elements are set to NULL ap_unparse_uri_components convert back to a URI char *ap_unparse_uri_components(pool *p, const uri_components *uptr, unsigned flags) Takes a filled-in uri_components, uptr, and makes a string containing the corresponding URI The string is allocated in p flags is a combination of none or more of the following: UNP_OMITSITEPART Leave out scheme://user:password@site:port UNP_OMITUSER Leave out the user UNP_OMITPASSWORD Leave out the password UNP_OMITUSERINFO Shorthand for UNP_OMITUSER|UNP_OMITPASSWORD UNP_REVEALPASSWORD Show the password (instead of replacing it with XXX) ap_pgethostbyname resolve a hostname struct hostent *ap_pgethostbyname(pool *p, const char *hostname) Essentially does the same as the standard function gethostbyname( ), except that the result is allocated in p instead of being temporary ap_pduphostent duplicate a hostent structure struct hostent *ap_pduphostent(pool *p, const struct hostent *hp) Duplicates hp (and everything it points at) in the pool p A.6.24 Miscellaneous Functions ap_child_terminate cause the current process to terminate void ap_child_terminate(request_rec *r) Makes this instance of Apache terminate after the current request has completed If the connection is a keepalive connection, keepalive is canceled ap_default_port return the default port for a request unsigned short ap_default_port(request_rec *r) Returns the default port number for the type of request handled by r In standard Apache this is always an HTTP request, so the return is always 80; but in Apache-SSL, for example, it depends on whether HTTP or HTTPS is in use ap_is_default_port check whether a port is the default port int ap_is_default_port(int port, request_rec *r) Returns if port is the default port for r or if not ap_default_port_for_scheme return the default port for a scheme unsigned short ap_default_port_for_scheme(const char *scheme_str) Returns the default port for the scheme scheme ap_http_method return the scheme for a request const char *ap_http_method(request_rec *r) Returns the default scheme for the type of request handled by r In standard Apache this is always an HTTP request, so the return is always http; but in Apache-SSL, for example, it depends on whether HTTP or HTTPS is in use ap_default_type returns default content type const char *ap_default_type(request_rec *r) Returns the default content type for the request r This is either set by the DefaultType directive or is text/plain ap_ get_basic_auth_pw get the password supplied for basic authentication int ap_ get_basic_auth_pw(request_rec *r, const char **pw) If a password has been set for basic authentication (by the client), its address is put in *pw Otherwise, an appropriate error is returned: DECLINED If the request does not require basic authentication SERVER_ERROR If no authentication domain name has been set (with AuthName) AUTH_REQUIRED If authentication is required but has not been sent by the client OK If the password has been put in *pw ap_ get_module_config get module-specific configuration information void *ap_ get_module_config(void *conf_vector, module *m) Gets the module-specific configuration set up by the module during startup conf_vector is usually either the per_dir_config from a request_rec or module_config from a server_rec See Chapter 21 for more information ap_ get_remote_logname get the login name of the client's user const char *ap_ get_remote_logname(request_rec *r) Returns the login name of the client's user if it can be found and if the facility has been enabled with the IdentityCheck directive Returns NULL otherwise ap_ get_server_name get the name of the current server const char *ap_ get_server_name(const request_rec *r) Gets the name of the server that is handling r If the UseCanonicalName directive is on, then it returns the name configured in the configuration file If UseCanonicalName is off, it returns the hostname used in the request — if there was one, or the configured name if not ap_ get_server_port get the port of the current server unsigned ap_ get_server_port(const request_rec *r) If UseCanonicalName is on, then returns the port configured for the server that is handling r If UseCanonicalName is off, returns the port of the connection if the request included a hostname; otherwise the configured port.[6] ap_is_initial_req is this the main request_rec? int ap_is_initial_req(request_rec *r) Returns if r is the main request_rec (as opposed to a subrequest or internal redirect) and otherwise ap_matches_request_vhost does a host match a request's virtual host? int ap_matches_request_vhost(request_rec *r, const char *host, unsigned port) Returns if host:port matches the virtual host that is handling r; otherwise ap_os_dso_load load a dynamic shared object (DSO) void *ap_os_dso_load(const char *path) Loads the dynamic shared object (that is, DLL, shared library, etc.) specified by path This has a different underlying implementation according to platform The return value is a handle that can be used by other DSO functions Returns NULL if path cannot be loaded ap_os_dso_unload unload a dynamic shared object void ap_os_dso_unload(void *handle) Unloads the dynamic shared object described by handle ap_os_dso_sym return the address of a symbol void *ap_os_dso_sym(void *handle, const char *symname) Returns the address of symname in the dynamic shared object referred to by handle If the platform mangles symbols in some way (for example, by prepending an underscore), this function does the same mangling before lookup Returns NULL if symname cannot be found or an error occurs ap_os_dso_error get a string describing a DSO error const char *ap_os_dso_error(void) If an error occurs with a DSO function, this function returns a string describing the error If no error has occurred, returns NULL ap_popendir an opendir( ) with cleanup DIR *ap_popendir(pool *p, const char *name) Essentially the same as the standard function opendir( ), except that it registers a cleanup function that will a closedir( ) A DIR created with this function should be closed with ap_pclosedir( ) (or left for the cleanup to close) Apart from that, the standard functions should be used ap_pclosedir close a DIR opened with ap_popendir( ) void ap_pclosedir(pool *p, DIR * d) Does a closedir( ) and cancels the cleanup registered by ap_popendir( ) This function should only be called on a DIR created with ap_popendir( ) ap_psignature create the server "signature" const char *ap_psignature(const char *prefix, request_rec *r) Creates a "signature" for the server handling r This can be nothing, the server name and port, or the server name and port hot-linked to the administrator's email address, depending on the setting of the ServerSignature directive Unless ServerSignature is off, the returned string has prefix prepended ap_vformatter general-purpose formatter int ap_vformatter(int (*flush_func)(ap_vformatter_buff *), ap_vformatter_buff *vbuff, const char *fmt, va_list ap) Because Apache has several requirements for formatting functions (e.g., ap_bprintf( ), ap_psprintf( )) and it is actually not possible to implement them safely using standard functions, Apache has its own printf( )-style routines This function is the interface to them It takes a buffer-flushing function as an argument and an ap_vformatter_buff structure, which looks like this: typedef struct { char *curpos; char *endpos; } ap_vformatter_buff; It also takes the usual format string, fmt, and varargs list, ap ap_vformatter( ) fills the buffer (at vbuff->curpos) until vbuff->curpos == vbuff->endpos; then flush_func( ) is called with vbuff as the argument flush_func( ) should empty the buffer and reset the values in vbuff to allow the formatting to proceed flush_func( ) is not called when formatting is complete (unless it happens to fill the buffer) It is the responsibility of the function that calls ap_vformatter( ) to finish things off Since flush_func( ) almost always needs more information than that found in vbuff, the following ghastly hack is frequently employed First, a structure with an [7] ap_vformatter_buff as its first element is defined: struct extra_data { ap_vformatter_buff vbuff; int some_extra_data; }; Next, the printf( )-style routine calls ap_vformatter with an instance of this structure: struct extra_data mine; mine.some_extra_data=123; ap_vformatter(my_flush,&mine.vbuff,fmt,ap); Finally, my_flush( ) does this: API_EXPORT(int) my_flush(ap_vformatter_buff *vbuff) { struct extra_data *pmine=(struct extra_data *)vbuff; assert(pmine->some_extra_data == 123); As you can probably guess, we don't entirely approve of this technique, but it works ap_vformatter( ) does all the usual formatting, except that %p has been changed to %pp, %pA formats a struct in_addr * as a.b.c.d , and %pI formats a struct sockaddr_in * as a.b.c.d:port The reason for these strange-looking formats is to take advantage of gcc 's format-string checking, which will make sure a %p corresponds to a pointer [1] Or, in other words, mail Since HTTP has elements borrowed from MIME and MIME is for mail, you can see the connection [2] Don't think that using this function makes shell scripts safe: it doesn't See Chapter 11 [3] In fact, exactly what Windows does with filenames is very poorly documented and is a seemingly endless source of security holes [4] This may seem perverse, but the idea is that by asking for a Content-Length, we are implicitly requesting that there is no Transfer-Encoding (at least, not a chunked one) Getting both is an error [5] Not really an option, in our view, but we didn't name the function [6] Though what practical difference this makes is somewhat mysterious to us [7] Of course, if you don't mind the hack being even more ghastly, it doesn't have to be first Colophon Our look is the result of reader comments, our own experimentation, and feedback from distribution channels Distinctive covers complement our distinctive approach to technical topics, breathing personality and life into potentially dry subjects The animal on the cover of Apache: The Definitive Guide, Third Edition, is an Appaloosa horse Developed by the Nez Perce Indians of northeastern Oregon, the name Appaloosa derives from the nearby Palouse River Although spotted horses are believed to be almost as old as the equine race itself-Cro-Magnon cave paintings depict spotted horses-the Appaloosa is the only established breed of spotted horse The Appaloosa was bred to be a hunting and war horse, and as such they have great stamina, are highly athletic and agile, and have docile temperaments When the Nez Perce, led by Chief Joseph, surrendered to the U.S Army in 1876 and were exiled to Oklahoma, the Appaloosa breed was almost eradicated In 1938 the Appaloosa Horse Club was formed in Moscow, Idaho, and the breed was revived The Horse Club now registers approximately 65,000 horses, making it the third largest registry in the world No longer a war horse, Appaloosas can be found in many equestrian venues, from trail riding to western competition to pleasure riding Jeffrey Holcomb was the production editor and copyeditor for Apache: The Definitive Guide, Third Edition Sheryl Avruch, Sarah Sherman, and Mary Anne Weeks Mayo provided quality control Genevieve d'Entremont, Judy Hoer, Sue Willing, and David Chu were the compositors Tom Dinse and Johnna VanHoose Dinse wrote the index Edie Freedman designed the cover of this book The cover image is a 19th-century engraving from the Dover Pictorial Archive Emma Colby produced the cover layout with QuarkXPress 4.1 using Adobe's ITC Garamond font David Futato designed the interior layout The text font is Linotype Birka; the heading font is Adobe Myriad Condensed; and the code font is LucasFont's TheSans Mono Condensed The illustrations that appear in the book were produced by Robert Romano and Jessamyn Read using Macromedia FreeHand and Adobe Photoshop The tip and warning icons were drawn by Christopher Bing This colophon was written by Clairemarie Fisher O'Leary The online edition of this book was created by the Safari production group (John Chodacki, Becki Maisch, and Madeleine Newell) using a set of Frame-to-XML conversion and cleanup tools written and maintained by Erik Ray, Benn Salter, John Chodacki, and Jeff Liggett ... and analyzes the headers It then applies the rules it finds in the Config file and takes the appropriate action The webmaster's main control over Apache is through the Config file The webmaster... rearranged the syntax a little As they stand, they save the reader having to break off and go to the Apache site 1.3 Apache and Networking At its core, Apache is about communication over networks Apache. .. change to the use of subnet masks These allow us to further subdivide the network by using more of the bits for the network number and less for the host number Their correct use is rather technical,

Ngày đăng: 12/03/2019, 16:39

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN