Cover | Table of Contents | Colophon
<method>://<host>/<absolute path URL (apURL)>
http, meaning that the browser should use
HTTP (Hypertext Transfer Protocol);
<host> is
www.butterthlies.com; and
<apURL> is "/
", meaning the top directory of the host. Using
HTTP/1.1, your browser might send the following request:GET / HTTP/1.1 Host: www.butterthlies.com
GET, but could equally be
PUT, POST,
DELETE, or CONNECT; the Uniform
Resource Identifier (URI) "/"; and the
version of the protocol we are using. It is then up to the web server
running on that host to make something of this message.
Port numbers below 1024 can only be used by the
superuser
(
> ping -c 5 www.apache.org
% ping -c 5 www.apache.org
PING www.apache.org (204.152.144.38): 56 data bytes
64 bytes from taz.apache.org (204.152.144.38): icmp_seq=0 ttl=247 time=1380 ms
64 bytes from taz.apache.org (204.152.144.38): icmp_seq=1 ttl=247 time=1930 ms
64 bytes from taz.apache.org (204.152.144.38): icmp_seq=2 ttl=247 time=1380 ms
64 bytes from taz.apache.org (204.152.144.38): icmp_seq=3 ttl=247 time=1230 ms
64 bytes from taz.apache.org (204.152.144.38): icmp_seq=4 ttl=247 time=1360 ms
--- www.apache.org ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss round-trip min/avg/
max = 1230/1456/1930 ms
The Unix server has a standalone Apache that listens to one or more
ports (port 80 by default) on one or more IP addresses mapped onto
the interfaces of its machine. In this mode (known as
standalone mode
), Apache actually runs several copies of
itself to handle multiple connections simultaneously.
The server is configured to use the Unix utility
inetd
, which listens on all ports it is
configured to handle. When a connection comes in, it determines from
its
configuration file,
/etc/inetd.conf, which service that port
corresponds to and runs the configured program, which can be an
Apache in inetd mode. It is worth noting that some of
the more advanced features of Apache are not supported in this mode,
so it should only be used in very simple cases. Support for this mode
may well be removed in future releases of Apache.
On Windows, there is a single process with multiple threads. Each
thread services a single connection. This currently limits Apache to
64 simultaneous connections, because there's a system limit of
64 objects for which you can wait at once. This is something of a
disadvantage because a busy site can have several hundred
simultaneous connections. It will probably be improved in Apache 2.0.http://www.freebsd.org, but sending $69.95 (plus
shipping) to Walnut Creek (at
http://www.cdrom.com) gets you four CD-ROMs with
more software on them than you can shake a stick at, including all
the source code, plus a 1750-page manual that should just about get
you going. Without Walnut Creek's manual, we think FreeBSD
would cost a lot more than $69.95 in spiritual self-improvement., and
some better shell than sh (we like
bash and ksh), so it might
be sensible to install them straightaway from their lurking places on
the CD-ROM.http://www.apache.org/. You can also load an
older version from the enclosed CD-ROM. You will get a compressed
file, with the extension .gz if it has been
gzipped, or .Z if it has been compressed. Most
Unix software available on the Web (including the Apache source code)
is compressed using gzip, a GNU compression
tool. If you don't have a copy, you will find one on our CD, or
you can get it from the Web.
uncompress <
apachename
>.tar.Z
gzip -d <
apachename
>.tar.gz
mv
<
apachename
>
<
apachename
>.tar
% tar xvf <
apachename
>.tar
http://www.apache.org/dist and click on the version you want, which will be in the
form of a self-installing .exe file (the
.exe extension is how you tell which one is the
Win32 Apache). Download it into, say, c:\temp
and then run it from the Win32 Start menu's Run option.> cd c:\<apache directory>> dir
Volume in drive C has no label
Volume Serial Number is 294C-14EE
Directory of C:\apache
. <DIR> 21/05/98 7:27 .
.. <DIR> 21/05/98 7:27 ..
DEISL1 ISU 12,818 29/07/98 15:12 DeIsL1.isu
HTDOCS <DIR> 29/07/98 15:12 htdocs
MODULES <DIR> 29/07/98 15:12 modules
ICONS <DIR> 29/07/98 15:12 icons
LOGS <DIR> 29/07/98 15:12 logs
CONF <DIR> 29/07/98 15:12 conf
CGI-BIN <DIR> 29/07/98 15:12 cgi-bin
ABOUT_~1 12,921 15/07/98 13:31 ABOUT_APACHE
ANNOUN~1 3,090 18/07/98 23:50 Announcement
KEYS 22,763 15/07/98 13:31 KEYS
LICENSE 2,907 31/03/98 13:52 LICENSE
APACHE EXE 3,072 19/07/98 11:47 Apache.exe
APACHE~1 DLL 247,808 19/07/98 12:11 ApacheCore.dll
MAKEFI~1 TMP 21,025 15/07/98 18:03 Makefile.tmpl
README 2,109 01/04/98 13:59 README
README~1 TXT 2,985 30/05/98 13:57 README-NT.TXT
INSTALL DLL 54,784 19/07/98 11:44 install.dll
_DEISREG ISR 147 29/07/98 15:12 _DEISREG.ISR
_ISREG32 DLL 40,960 23/04/97 1:16 _ISREG32.DLL
13 file(s) 427,389 bytes
8 dir(s) 520,835,072 bytes free
httpd -d /usr/www/site.for_instance
apache -d c:/usr/www/site.for_instance
httpd -d /usr/www/site.for_instance
apache -d c:/usr/www/site.for_instance
-D
name
<IfDefine> directives.-d
directory
ServerRoot
directory.-f
filename
ServerConfig
file.
-C "
directive
"
-c "
directive
"
-v
-V
-h
-l
The next step is to edit the configuration files for the server. In the subdirectory called conf you should find distribution versions of the three configuration files: srm.conf-dist, access.conf-dist, and httpd.conf-dist.
-d flag (notice
the full pathname to the site.toddle directory):% httpd -d /usr/www/site.toddle
% cat > /usr/local/bin/go httpd -d `pwd` ^d
^d is shorthand for CTRL-D, which ends the input
and gets your prompt back. This go will work on
every site.% chmod +x /usr/local/bin/go % go
ps
vary from Unix
to Unix):% ps -aux
ps
-aux and execute the Unix
utility
kill:% kill PID
PidFile directive), you can write yourself a
little script, as follows:kill `cat /usr/www/site.toddle/logs/httpd.pid`
httpd -d `pwd`
pwd | read path kill `cat $path/logs/httpd.pid`
>ping 127.0.0.1
Pinging 127.0.0.1 with 32 bytes of data: Reply from 127.0.0.1: bytes=32 time<10ms TTL=32 ....
>cd "\Program Files\apache"
>apache -i
>apache -u
>net start apache >net stop apache
127.0.0.1 localhost 192.168.123.2 www.butterthlies.com 192.168.123.2 sales.butterthlies.com 192.168.123.3 sales-IP.butterthlies.com 192.168.124.1 www.faraway.com
% httpd -d /usr/www/site.simple
>apache -d c:/usr/www/site.simple
127.0.0.1 localhost 192.168.123.2 www.butterthlies.com 192.168.123.2 sales.butterthlies.com 192.168.123.3 sales-IP.butterthlies.com 192.168.124.1 www.faraway.com
% httpd -d /usr/www/site.simple
>apache -d c:/usr/www/site.simple
User webuser Group webgroup ServerName localhost DocumentRoot /usr/www/site.first/htdocs TransferLog logs/access_log
AccessConfig and ResourceConfig
here. If set with /dev/null
(NUL under Win32), they disable the
srm.conf and access.conf
files, and were formerly required if those files were absent.
However, new versions of Apache ignore these files if they are not
present, so the directives are no longer required.
If you are using Win32, note that the User and
Group directives are not supported, so these can
be removed.<html> <h1> Welcome to Butterthlies Inc</h1> <h2>Summer Catalog</h2> <p> All our cards are available in packs of 20 at $2 a pack. There is a 10% discount if you order more than 100. </p> <hr> <p> Style 2315 <p align=center> <img src="bench.jpg" alt="Picture of a bench"> <p align=center> Be BOLD on the bench <hr> <p> Style 2316 <p align=center> <img src="hen.jpg" ALT="Picture of a hencoop like a pagoda"> <p align=center> Get SCRAMBLED in the henhouse <HR> <p> Style 2317 <p align=center> <img src="tree.jpg" alt="Very nice picture of tree"> <p align=center> Get HIGH in the treehouse <hr> <p> Style 2318 <p align=center> <img src="bath.jpg" alt="Rather puzzling picture of a bathtub"> <p align=center> Get DIRTY in the bath <hr> <p align=right> Postcards designed by Harriet@alart.demon.co.uk <hr> <br> Butterthlies Inc, Hopeful City, Nevada 99999 </br> </HTML>
<VirtualHost>—the webmaster can, in
effect, set up a large number of individual servers run by a single
invocation of Apache. This will make more sense when you get to Section 3.5, further on in this
chapter.<VirtualHost host[:port]> ... </VirtualHost> Server config
<VirtualHost>
directive within a Config file acts like a tag in HTML: it introduces
a block of text containing directives referring to one host; when
we're finished with it, we stop with
</VirtualHost>. For example:.... <VirtualHost www.butterthlies.com> ServerAdmin sales@butterthlies.com DocumentRoot /usr/www/site.virtual/htdocs/customers ServerName www.butterthlies.com ErrorLog /usr/www/site.virtual/name-based/logs/error_log TransferLog /usr/www/site.virtual/name-based/logs/access_log </VirtualHost> ...
<VirtualHost> also specifies which IP
address we're hosting and, optionally, the port. If
port is not specified, the default port is
used, which is either the standard HTTP port, 80, or the port
specified in a Port directive.
host can also be _default_
, in which case it matches anything no other
<VirtualHost> section matches.<VirtualHost> directive has three
analogues that also limit the application of other directives:<Directory>
<Files>
ServerName hostname
Server config, virtual host
ServerName
gives the hostname of the server to use
when creating redirection URLs, that is, if you use a
<Location> directive or access a directory
without a trailing "/".
UseCanonicalName on|off
Default: on
Server config, virtual host, directory, .htaccess
UseCanonical-Name is on (the
default), then the hostname and port used in the redirect will be
those set by ServerName and
Port. If it is off, then the
name and port used will be the ones in the original request.UseCanonicalName switched
on
, the user will be directed
to http://www.domain.com/somedir/, whereas with
UseCanonicalName switched off,
he or she will be redirected to http://www/somedir/. An obvious case in which
this is useful is when user authentication is switched on: reusing
the server name that the user typed means they won't be asked
to reauthenticate when the server name appears to the browser to have
changed. More obscure cases relate to name/address translation caused
by some firewalling techniques.ServerAdmin email_address
Server config, virtual host
X flag, which is
what you would do in real operation, Apache launches a number of
child versions of itself so that any incoming request can be
instantly dealt with. This is an excellent scheme, but we need some
way of controlling this sprawl of software. The necessary directives
are there to do it.
MaxClients number
Default number: 150
Server config
MaxRequestsPerChild number
Default number: 30
Server config
MaxSpareServers number
Default number: 10
Server config
MinSpareServers number
Default number
ThreadsPerChild number
Default number: 50
Server config
ThreadsPerChild may
suggest that there can be more than one child process in a Win32
installation, but this is not currently the case.
NameVirtualHost
directive. The possible combinations
of IP-based and name-based hosts can become quite complex. A full
explanation with examples and the underlying theology can be found at
http://www.apache.org/docs/vhosts but it has to
be said that several of the possible permutations are unlikely to be
very useful in practice.
User webuser Group webgroup NameVirtualHost 192.168.123.2 <VirtualHost www.butterthlies.com> ServerAdmin sales@butterthlies.com DocumentRoot /usr/www/site.virtual/htdocs/customers ServerName www.butterthlies.com ErrorLog /usr/www/site.virtual/name-based/logs/error_log TransferLog /usr/www/site.virtual/name-based/logs/access_log </VirtualHost> <VirtualHost sales.butterthlies.com> ServerAdmin sales@butterthlies.com DocumentRoot /usr/www/site.virtual/htdocs/salesmen ServerName sales.butterthlies.com ErrorLog /usr/www/site.virtual/name-based/logs/error_log TransferLog /usr/www/site.virtual/name-based/logs/access_log </VirtualHost>
ServerType, User,
TypesConfig, or ServerRoot (none of these directives can apply to a virtual host,
since they are global to all servers, which is why you have to run
two copies to get the desired effect). If you are expecting a lot of
hits, you should try to avoid running more than one copy, as doing so
will generally load the machine more.User webuser Group webgroup ServerName www.butterthlies.com DocumentRoot /usr/www/site.twocopy/customers/htdocs BindAddress www.butterthlies.com TransferLog logs/access_log
User webuser Group webgroup ServerName sales.butterthlies.com DocumentRoot /usr/www/site.twocopy/sales/htdocs Listen sales-not-vh.butterthlies.com:80 TransferLog logs/access_log