3.1. More and Better Web Sites: site.simple
We are now in a position to start creating real(ish) web sites, which
can be found on the accompanying CD-ROM. For the sake of a little
extra realism, we will base them loosely round a simple web business,
Butterthlies, Inc., that creates and sells picture postcards. We need
to give it some web addresses, but since we don't yet want to
venture into the outside world, they should be variants on your own
network ID so that all the machines in the network realize that they
don't have to go out on the Web to make contact. For instance,
we edited the \windows\hosts file on the Win95
machine running the browser and the /etc/hosts
file on the Unix machine running the server to read as follows:
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
localhost is obligatory, so we left it in, but
you should not make any server requests to it since the results are
likely to be confusing.
You probably need to consult your network manager to make similar
arrangements.
site.simple is site.toddle
with a few small changes. The script
go is different in that it refers to
... /site.simple/conf/httpd.conf rather than
... /site.toddle/conf/httpd.conf.
Unix:
% httpd -d /usr/www/site.simple
Win32:
>apache -d c:/usr/www/site.simple
This will be true of each site in the demonstration setup, so we will
not mention it again.
From here on there will be minimal differences between the server
setups necessary for Win32 and those for Unix. Unless one or the
other is specifically mentioned, you should assume that the text
refers to both.
It would be nice to have a log of what goes on. In the first edition
of this book we found that a file access_log was
created automatically in ...site.simple/logs. In
a rather bizarre move since then, the Apache Group has broken
backward compatibility and now requires you to mention the log file
explicitly in the Config file using the
TransferLog directive.
The ... /conf/httpd.conf file now contains the
following:
User webuser
Group webgroup
ServerName localhost
DocumentRoot /usr/www/site.simple/htdocs
TransferLog logs/access_log
In ... /htdocs we have, as before,
1.txt :
hullo world from site.simple!
Now, type go on the server. Switch to the client
machine and retrieve
http://www.butterthlies.com. You should see:
Index of /
. Parent Directory
. 1.txt
Click on 1.txt for an inspirational message as
before.
This all seems satisfactory, but there is a hidden mystery. We get
the same result if we connect to
http://sales.butterthlies.com. Why is this? Why,
since we have not mentioned either of these URLs or their IP
addresses in the configuration file on
site.simple, do we get any response at all?
The answer is that when we configured the machine the server runs on,
we told the network interface to respond to any
of these IP addresses:
192.168.123.2
192.168.123.3
Back on the server, stop Apache with ^C (or
whatever your kill character is) and look at the log files. In
... /logs/access_log, you should see something
like this:
192.168.123.1 - - [<date-time>] "GET / HTTP/1.1" 200 177
200 is the response code (meaning "OK, cool,
fine"), and 177 is the number of bytes
transferred. In ... /logs/error_log, there
should be nothing because nothing went wrong. However, it is a good
habit to look there from time to time, though you have to make sure
that the date and time logged correspond to the problem you are
investigating. It is easy to fool yourself with some long-gone drama.
Life being what it is, things can go wrong, and the client can ask
for something the server can't provide. It makes sense to allow
for this with the ErrorDocument command.