Top Banner
COMP3170 Web Based Applications Dr. Curtis Gittens Lecture II
24
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • COMP3170 Web Based Applications

    Dr. Curtis GittensLecture 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

    The default situation is when a user visits a website using a URI that asks for a resource e.g.

    Apache uses httpd.confto determine how to respond to all requests

    A file request only involves theDocumentRootdirective. A directory request involves the DocumentRoot and DirectoryIndexdirectives.

    4

    Server passes default file back to user

    Server receives request, checks its configuration file httpd.conf for the

    document root

    Fetches the file

    Adds the URL-Path to the end of the DocumentRootindicated in the httpd.conffile

    Apache server listens on port 80 for request

    User sends a plain IP address URL

    Looks at the DirectoryIndexdirective for a default file to display if a directory is requested

    2

    1

    3

    4

    5

    6

    7

    OR

    http://www.fb.com/login.html

  • The Directives

    5

  • 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

    Example6

    Document Root:- /var/wwwURL:- http://www.mydomain.com/myfile.htmlDirectory/file referred to: /var/www/myfile.html

  • 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

  • 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

    ExampleDirectoryIndex index.html index.php index.txt /cgi-

    bin/index.pl

    8

  • 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 directive2. 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 linkSimply 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

    ScriptAliasHas 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 accessibleDefault 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

    19

    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

  • User Directories for Web Pages

    20

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

  • Accessing the FilesystemUsing 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 looks for var/www/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