PI_L08B by aashu4uiit

VIEWS: 4 PAGES: 26

									Configuring Directives and Virtual Hosts

Copyright © 2004, Oracle. All rights reserved.

Objectives

After completing this lesson, you should be able to do the following: • Describe the configuration directives and their scope • Describe the process of merging containers and contents • Configure directories, and enable directory indexes • Set up virtual hosts • Use configuration directives such as Option, Alias, and ScriptAlias

8B-2

Copyright © 2004, Oracle. All rights reserved.

Configuration Contexts

Server Context
httpd.conf <VirtualHost>

Directory Context
.htaccess AuthConfig Limits Options FileInfo

1

2

<Directory>

3

<Files>

4
<Location>

5

Indexes

8B-3

Copyright © 2004, Oracle. All rights reserved.

Container Directives

• • •

Container directives have opening and closing tags that surround other directives. Every directive within a container's tag affects only what that container refers to. Any directive that does not appear within a container applies to the entire server.
<VirtualHost> <Directory>, <DirectoryMatch> <Location>, <LocationMatch> <Files>, <FilesMatch> <Limit>, <LimitExcept>

8B-5

Copyright © 2004, Oracle. All rights reserved.

Block Directives

Block directives limit the scope of application of other directives within them.
<IfModule mod_userdir.c> UserDir public_html </IfModule>

8B-6

Copyright © 2004, Oracle. All rights reserved.

Merging Containers and Contents

The directives are merged in the following order: 1. Directives inside nonregular expression Directory containers and .htaccess directives are processed simultaneously, with the .htaccess directives overriding the directives of the Directory container. 2. DirectoryMatch containers are applied. 3. Directives from the Files and FilesMatch containers are merged. 4. The last ones to be applied are Location and LocationMatch.

8B-7

Copyright © 2004, Oracle. All rights reserved.

Context Merging and Inheritance

• • • •

To match objects at the file-system level, use <Directory> or <Files>. To match URLs, use <Location>. <Location> containers are processed last, although the URL is what the user applies first. Using an <Options> directive inside a <Files> section has no effect.

8B-8

Copyright © 2004, Oracle. All rights reserved.

Where the Directives Can Be Specified

•

The directives can be specified within:
– Server-level configuration section – Virtual host container – Directory (including Location and Files) container – .htaccess file

•

Limit or LimitExcept containers may not include other containers, but may include any other directive.

8B-9

Copyright © 2004, Oracle. All rights reserved.

<Directory> Directive

The Directory contains a group of directives that apply to the named directory and subdirectories.
<Directory /> Options none AllowOverride none </Directory> <Directory /home/www/*> AllowOverride all </Directory>

8B-11

Copyright © 2004, Oracle. All rights reserved.

<Files> and <Location>

•

<Files> matches files instead of directories:
<Directory /ias20/public/images> <Files *.gif> SetHandler /cgi-bin/process-image.cgi </Files> </Directory>

•

<Location> applies to a URL:
<Location /server-info> SetHandler server-info </Location>

8B-12

Copyright © 2004, Oracle. All rights reserved.

<VirtualHost> Directive
Allows additional hosts and Web sites to be defined alongside the main server:
<VirtualHost www.host1.com> DocumentRoot /usr/virtual/htdocs/customers ServerName www.host1.com ErrorLog /usr/virtual/h1/logs/error_log </VirtualHost> <VirtualHost www.host2.com> DocumentRoot /usr/virtual/htdocs/internal ServerName www.host2.com ErrorLog /usr/virtual/h2/logs/error_log </VirtualHost>
8B-14 Copyright © 2004, Oracle. All rights reserved.

Defining Virtual Hosts

• •

IP-based and name-based virtual hosts are defined with the VirtualHost container directive. The VirtualHost container includes a set of alternative directives to the main server, such as:
ServerAdmin ServerName DocumentRoot ErrorLog CustomLog Directory Location

8B-15

Copyright © 2004, Oracle. All rights reserved.

Using IP-Based Virtual Hosts

A virtual host can be IP-based:
<VirtualHost 130.35.174.159 205.134.38.199> ServerName www.oracle.com ServerAdmin Webmaster@oracle.com DocumentRoot /oras/oracle/www ErrorLog /oras/oracle/logs/error_log TransferLog /oras/oracle/logs/access_log </VirtualHost>

8B-17

Copyright © 2004, Oracle. All rights reserved.

Using Name-Based Virtual Hosts
A virtual host can be name based:
NameVirtualHost 205.134.38.199 VirtualHost www.host1.com> DocumentRoot /usr/virtual/htdocs/customers ServerName www.host1.com ErrorLog /usr/virtual/h1/logs/error_log </VirtualHost> <VirtualHost www.host2.com> DocumentRoot /usr/virtual/htdocs/internal ServerName www.host2.com ErrorLog /usr/virtual/h2/logs/error_log </VirtualHost>

8B-18

Copyright © 2004, Oracle. All rights reserved.

Configuring Virtual Hosts

8B-19

Copyright © 2004, Oracle. All rights reserved.

Controlling Allowed Features

•

Use Options to enable and disable features:
Options ExecCGI FollowSymLinks

•

Use AllowOverride to control overrides:
AllowOverride FileInfo Indexes

8B-20

Copyright © 2004, Oracle. All rights reserved.

Options Parameters

• • • • • • • • •

All ExecCGI FollowSymLinks SymLinksIfOwnerMatch Includes IncludesNOEXEC Indexes MultiViews None

8B-21

Copyright © 2004, Oracle. All rights reserved.

Using Options
Example A
# Using Absolute Options <Directory /web/docs> Options Indexes FollowSymLinks </Directory> <Directory /web/docs/spec> Options Includes </Directory>

Example B
# Using Relative Options <Directory /web/docs> Options Indexes FollowSymLinks </Directory> <Directory /web/docs/spec> Options +Includes -Indexes </Directory>
8B-23 Copyright © 2004, Oracle. All rights reserved.

Enabling Server-Side Includes (SSI)

An example of using Options to enable the execution of SSI:
<Location /ssidocs> Options +Includes AddHandler server-parsed .shtml </Location>

8B-24

Copyright © 2004, Oracle. All rights reserved.

Overriding Directives with the Per-Directory Configuration
• Oracle HTTP Server allows the server configuration to be supplemented with the following per-directory configuration files:
– .htaccess file – AllowOverride All, AuthConfig, Limit, FileInfo, Indexes, Options, None

•

Using directives outside of the standard configuration files may cause the configuration repository to be out of sync.

8B-25

Copyright © 2004, Oracle. All rights reserved.

Directory Indexing

•

Enable or disable directory indexing:
Options +Indexes

•

Use DirectoryIndex to change the default file displayed:
DirectoryIndex index.html index.htm

•

Specify a nonrelative URL as a last resource to prevent generating an index for the directory.
DirectoryIndex index.html /cgi-bin/error404.cgi

8B-27

Copyright © 2004, Oracle. All rights reserved.

Controlling Directory Listings with IndexIgnore
Prevent files from appearing in the directory listing by using the IndexIgnore directive:
IndexIgnore .??* *~ *# *.bak HEADER* README*

8B-29

Copyright © 2004, Oracle. All rights reserved.

Error and Response Handling

Error and response codes:
Category 100+ 200+ 300+ 400+ 500+ Meaning Informational Client request successful Client request redirected, further action necessary Client request incomplete Server errors

The ErrorDocument directive:
ErrorDocument 404 "Sorry, document not found ErrorDocument 404 /errors/notfound.html ErrorDocument 500 /errors/fake404.cgi
8B-30 Copyright © 2004, Oracle. All rights reserved.

Expires Header

Expires headers are used to control the caching behavior for Web content. • To enable the sending of Expires headers:
ExpiresActive on

•

To set a default expiration time:

ExpiresDefault A2419200 ExpiresDefault M86400 ExpiresDefault "access plus 1 month"

•

To set expiration times by media type:

ExpiresByType image/gif A2419200
8B-32 Copyright © 2004, Oracle. All rights reserved.

Alias, AliasMatch, and ScriptAlias

Aliases allow accesses to resources from a location other than the DocumentRoot directory: • Use Alias to store documents elsewhere:
Alias /soapdocs/ /ias/soap/

•

AliasMatch /images/(.*)\.gif$ /ias/images/$1.gif

AliasMatch allows you to use regular expressions:

•

Use ScriptAlias to store scripts elsewhere and mark them as CGI scripts:
ScriptAlias /cgi-bin/ /ias/Apache/Apache/cgi-bin/

8B-34

Copyright © 2004, Oracle. All rights reserved.

Summary

In this lesson, you should have learned how to: • • • • Use the configuration directives and their scope Configure directories, and enable directory indexes Set up virtual hosts Use configuration directives such as Option, Alias, and ScriptAlias

8B-35

Copyright © 2004, Oracle. All rights reserved.


								
To top