エイリアス(Alias)
クライアントに公開するコンテンツはドキュメントルート以下のディレクトリに設置する必要がありますが、エイリアスを使うことで全然別のディレクトリにあるファイルをドキュメントルートの配下に配置されているように見せかけることが出来ます。
Alias リクエストのURLパス 実際のディレクトリ
クライアントからのリクエストに含まれるURLのパスが、サーバ上の実際のどのディレクトリに対応するのかを指定します。
それでは「httpd.conf」ファイルで「Alias」で検索してみてください。272行目付近に次の記述が見つかります。
<IfModule alias_module>
#
# Redirect: Allows you to tell clients about documents that used to
# exist in your server's namespace, but do not anymore. The client
# will make a new request for the document at its new location.
# Example:
# Redirect permanent /foo http://localhost/bar
#
# Alias: Maps web paths into filesystem paths and is used to
# access content that does not live under the DocumentRoot.
# Example:
# Alias /webpath /full/filesystem/path
#
# If you include a trailing / on /webpath then the server will
# require it to be present in the URL. You will also likely
# need to provide a <Directory> section to allow access to
# the filesystem path.
#
# ScriptAlias: This controls which directories contain server scripts.
# ScriptAliases are essentially the same as Aliases, except that
# documents in the target directory are treated as applications and
# run by the server when requested rather than as documents sent to the
# client. The same rules about trailing "/" apply to ScriptAlias
# directives as to Alias.
#
ScriptAlias /cgi-bin/ "D:/Apache Group/Apache2.2/cgi-bin/"
</IfModule>
Aliasを使わない場合を考えてみます。ドキュメントルートが「D:/Apache Group/Apache2.2/htdocs」だった場合にクライアントから「http://localhost/sub/index.html」というリクエストがあった場合は次のようになります。
http://localhost/sub/index.html D:/Apache Group/Apache2.2/htdocs/sub/index.html
これに対して次のように「Alias」を設定してみます。
Alias /sub/ "D:/Apache Group/data/"
この場合はクライアントから「http://localhost/sub/index.html」というリクエストがあった場合は次のようになります。
http://localhost/sub/index.html D:/Apache Group/data/index.html
「Alias」を設定することで、Apacheのドキュメントルート以下に限定せず(Apacheが含まれているディレクトリ以外でも)ドキュメントの設置が可能となります。
テスト
では実際に試してみます。まず「D:/Apache Group/data/」と言うディレクトリを作成し、そのディレクトリの中に下記のHTMLファイルを設置します。
そして「Alias」に関する設定を追加します。
<IfModule alias_module>
#
# Redirect: Allows you to tell clients about documents that used to
# exist in your server's namespace, but do not anymore. The client
# will make a new request for the document at its new location.
# Example:
# Redirect permanent /foo http://localhost/bar
#
# Alias: Maps web paths into filesystem paths and is used to
# access content that does not live under the DocumentRoot.
# Example:
# Alias /webpath /full/filesystem/path
#
# If you include a trailing / on /webpath then the server will
# require it to be present in the URL. You will also likely
# need to provide a <Directory> section to allow access to
# the filesystem path.
Alias /data/ "D:/Apache Group/data/"
<Directory "D:/Apache Group/data">
Allow from all
</Directory>
#
# ScriptAlias: This controls which directories contain server scripts.
# ScriptAliases are essentially the same as Aliases, except that
# documents in the target directory are treated as applications and
# run by the server when requested rather than as documents sent to the
# client. The same rules about trailing "/" apply to ScriptAlias
# directives as to Alias.
#
ScriptAlias /cgi-bin/ "D:/Apache Group/Apache2.2/cgi-bin/"
</IfModule>
※ディレクトリに対してアクセス許可が必要なため「Allow from all」を設定してあります。
ブラウザを立ち上げて頂き次のURLへアクセスして下さい。
http://localhost/data/hello.html
ドキュメントルート以外のディレクトリに設置されたファイルに対して、エイリアスを使って外部からアクセスすることが出来ました。
( Written by Tatsuo Ikura )

AdminWeb