Servers 101 49
ServerThe Unix
Servers 101
Web Design in a Nutshell, eMatter Edition
not necessarily appear in the URL that points to the document, so it is important to
know what your root directory is when uploading your files.
For example, if the root directory on littlechair.com is/users/httpd/www/and a
browser makes a request forhttp://www.littlechair.com/super/cool.html, the server
actually retrieves/users/httpd/www/super/cool.html.This, of course, is invisible to
the user.
Index files
A forward slash (/) at the end of a URL indicates that the URL is pointing to a
directory, not a file. By default, servers display the contents of the directory speci-
fied in the URL. Most servers are configured, however, to display a specific file,
called theindex file, instead of the directory list. The index file is generally named
index.html, but on some servers it may be namedwelcome.htmlordefault.html.
This is another small variation you will need to confirm with your server
administrator.
If the server is configured to look for the index file and does not find one, the
directory contents may be displayed instead, leaving your files vulnerable to
snooping. For this reason, it is a good idea to always name some page (usually the
main page) in each directory “index.html” (or an otherwise specified name).
HTTP response header
Once the server locates the file, it sends the contents of that file back to the
browser, along with some HTTP response headers. The headers provide the
browser with information about the arriving file, including its media type (also
known as “content type” or “MIME type”). Usually, the server will determine the
format from the file’s suffix; for example, a file with the suffix .gif is taken to be an
image file.
The browser reads the header information and determines how to handle the file,
either displaying it in the window or launching the appropriate helper application
or plug-in. MIME types are discussed further at the end of this chapter.
CGI scripts
Instead of pointing to an HTML file, a URL may request that a CGI program be
run. CGI stands for Common Gateway Interface, and it’s what allows the web
server to communicate with other programs (CGI scripts) that are running on the
server. CGI scripts are commonly written in the Perl, C, or C++ languages.
CGI scripts can be used to perform a wide variety of functions such as searching,
server-side imagemap handling, and gaming; however, their most common usage
is forms processing. A typical CGI script is examined in Chapter 12,Forms.
Most server administrators follow the convention of keeping CGI scripts in a
special directory namedcgi-bin(short for CGI-binaries). Keeping them in one
directory makes it easier to manage and secure the server. When a CGI script is
requested by the browser, the server performs the function and returns the
dynamic content to the browser.