You are on page 1of 24

COMP3170 Web Based

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
–Describe how the UserDir directive works to make a
user’s 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

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

checks its configuration file httpd.conf to determine how to respond to all requests A file request only involves the DocumentRoot directive. 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 3 Server receives request.g. A directory request involves the DocumentRoot and DirectoryIndex directives.conf file 4 .com/login.fb.conf for the document root Adds the URL-Path to the 4 end of the DocumentRoot indicated in the httpd.html Apache uses httpd.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. http://www.

The Directives 5 .

com/myfile.html 6 ./var/www URL:.html Directory/file referred to: /var/www/myfile.mydomain.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:.http://www.

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 7 .

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

then say that as well.Clear as Mud? Write down two things from the lecture so far that are the most unclear to you. If there is nothing. 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 user’s request .

Web Access for Files Outside the Document Root Options for making files outside the Web file system accessible to the web 11 .

html –Using the Alias directive to map any part of the file system into the web space.html /var/www/foo. ▪ Example: Alias /mywebspace /dir/out/side/doc/root/ 12 .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.

but marks the directory as containing CGI scripts to be used by the CGI script handler 13 .Accessing “Outside” Files ▪ ScriptAlias –Has the same behaviour as Alias.

User Directories for the Web 14 .

user directories can be accessed using ~username ▪ The module userdir extends this to the web ▪ Files in a user’s directory can be accessed via the URL http://www.somedomain.User Directories for Web Pages ▪ In *NIX ▪ Direct access is not given to the user’s directory 15 .

User Directories for Web Pages ▪ The UserDir directive is used to specify a subdirectory in the user’s directory that is web accessible –Default setting is public_html –If the user’s home directory is /home/jsmith.html 16 . then Apache would retrieve the file: /home/jsmith/public_html/foo.

User Directories for Web Pages 17 .

User Directories for Web Pages 18 .

View the contents of the public_html directory 19 . dgittens subdirectory and view it’s contents where we see the public_html subdirectory 2. Go to the user.User Directories for Web Pages 1 2 1.

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 .

/var/www/html etc ▪ A relative path starts either with dot ‘. then where are these files located? . ..’ or a directory name without a preceding / ▪ Examples: If the current directory is /home/usr/here./foo.txt 22 .txt.Relative and Absolute Paths ▪ An absolute path in *NIX systems starts with / –Example: /etc/apache2. ‘. dot-dot.’./dir/other. dir/another.txt..

html 23 .html –<a href=“/index.html”> looks for var/www/index.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.

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 user’s 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 .