Step 4: Mapping and Accessing Resources

Web servers are resource servers. They deliver precreated content, such as HTML pages or JPEG images, as well as dynamic content from resource-generating applications running on the servers.

Before the web server can deliver content to the client, it needs to identify the source of the content, by mapping the URI from the request message to the proper content or content generator on the web server.


Web servers support different kinds of resource mapping, but the simplest form of resource mapping uses the request URI to name a file in the web server’s filesystem. Typically, a special folder in the web server filesystem is reserved for web content. This folder is called the document root, or docroot . The web server takes the URI from the request message and appends it to the document root.

In Figure 5-8, a request arrives for /specials/saw-blade.gif. The web server in this example has document root /usr/local/httpd/files. The web server returns the file /usr/local/httpd/files/specials/saw-blade.gif.

Mapping request URI to local web server resource

Figure 5-8. Mapping request URI to local web server resource

To set the document root for an Apache web server, add a DocumentRoot line to the httpd.conf configuration file:

DocumentRoot /usr/local/httpd/files

Servers are careful not to let relative URLs back up out of a docroot and expose other parts of the filesystem. For example, most mature ...

Get HTTP: The Definitive Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.