Sie sind auf Seite 1von 24

COMP3170 Web Based

Applications
Dr. Curtis Gittens
Lecture II

Learning Objectives
By the end of this lecture you will be able to:
Describe the process Apache uses to retrieve files
when a user makes a request
Describe the two main directives involved in file
retrieval
Describe how the UserDir directive works to make a
users directory Web accessible
Differentiate between the DocumentRoot and
DirectoryIndex directives
Differentiate between the different methods for
accessing files that are outside the document root
Differentiate absolute from relative paths
2

Quick Overview of How


Apache Accesses Web Pages
a brief discussion on how apache serves up web pages,
determines web directories and use absolute and relative
paths in web documents
3

How Apache Serves Up Web Pages


User sends a plain
IP address URL

The default situation is


when a user visits a
website using a URI that
asks for a resource e.g.
http://www.fb.com/login.html
Apache uses httpd.conf
to determine how to
respond to all requests
A file request only
involves the
DocumentRoot
directive. A directory
request involves the
DocumentRoot and
DirectoryIndex
directives.

1
2

Apache server
listens on port 80
for request
Server passes
default file back 7
to user

6
Fetches the file

Looks at the
DirectoryIndex
directive for a default
file to display if a
directory is
5
requested

OR

Server receives
request, checks its
configuration file
httpd.conf for the
document root
Adds the URL-Path to the 4
end of the DocumentRoot
indicated in the httpd.conf
file
4

The Directives

The DocumentRoot Directive


Sets the directory from which Apache serves files
for requests
Default value: /usr/local/apache/htdocs

Course server values: /var/www


The path specified in the URL received is
appended to the document root

This makes the actual path that is used to


retrieve the file
Example

Document Root:- /var/www


URL:- http://www.mydomain.com/myfile.html
Directory/file referred to: /var/www/myfile.html
6

The DirectoryIndex Directive


Sets the list of resources (files) to look for when
the client requests the directory by specifying a /
at the end of the URL
Note: When a trailing / is not specified, Apache
rewrites the URL to add the trailing slash and
then view it as a directory index request

The DirectoryIndex Directive


The resources (files, videos, etc.) are searched for
in the order specified
If none found and Indexes is set, it returns a
listing of the directory requested
Example
DirectoryIndex index.html index.php index.txt /cgibin/index.pl

Clear as Mud?
Write down
two things
from the
lecture so far
that are the
most unclear
to you. If there
is nothing,
then say that
as well.
Be prepared
to share!

In Your Own Words

1. Explain the difference between the DocumentRoot and the DirectoryIndex directive
2. Write down what you can remember about how Apache retrieves files based on a
users request

Web Access for Files


Outside the Document Root
Options for making files outside the Web file system
accessible to the web

11

Accessing Outside Files


Create a symbolic link
Simply make a symbolic link in the document root
of the files you want accessed by the web server
Example given /var/www as document root
ln s /dir/out/side/doc/root/foo.html
/var/www/foo.html

Using the Alias directive to map any part of the file


system into the web space.
Example: Alias /mywebspace /dir/out/side/doc/root/

12

Accessing Outside Files


ScriptAlias
Has the same behaviour as Alias, but marks the
directory as containing CGI scripts to be used by the
CGI script handler

13

User Directories for the


Web

14

User Directories for Web Pages


In *NIX systems, user directories can be accessed
using ~username
The module userdir extends this to the web

Files in a users directory can be accessed via the


URL
http://www.somedomain.com/~user/foo.html
Direct access is not given to the users directory

15

User Directories for Web Pages


The UserDir directive is used to specify a
subdirectory in the users directory that is web
accessible
Default setting is public_html
If the users home directory is /home/jsmith, then
Apache would retrieve the file:
/home/jsmith/public_html/foo.html

16

User Directories for Web Pages

17

User Directories for Web Pages

18

User Directories for Web Pages


1
2

1. Go to the user, dgittens subdirectory and view its contents where we see the
public_html subdirectory
2. View the contents of the public_html directory
19

User Directories for Web Pages

Enter the URL in the


browser for ~dgittens/ to
view the index.html
document over the Web

20

Accessing the Filesystem


Using Relative and
Absolute Paths

21

Relative and Absolute Paths


An absolute path in *NIX systems starts with /
Example: /etc/apache2, /var/www/html etc

A relative path starts either with dot ., dot-dot,


.. or a directory name without a preceding /
Examples: If the current directory is
/home/usr/here, then where are these files
located? ./foo.txt, ../dir/other.txt, dir/another.txt

22

Relative and Absolute Paths


Apache views paths based on the document root
These examples assume document root is /var/www
<a href=index.html> looks for var/www/index.html
<a href=/index.html> looks for /var/www/index.html

23

Summary
In this lecture we:
Described how Apache retrieve files when a user
makes a request
Described the two main directives involved in file
retrieval
Described how the UserDir directive works to make
a users directory Web accessible
Discussed how the DocumentRoot and
DirectoryIndex directives differ
Examined the different methods for accessing files
that are outside the document root
Discuss how absolute and relative paths differ
24

Das könnte Ihnen auch gefallen