그러냐

아파치 디렉토리 리스트 보이게 하기 본문

Linux

아파치 디렉토리 리스트 보이게 하기

관절분리 2016. 1. 28. 11:51
반응형

Directory Listing Configuration

Here we describe various types of things that the server can send when you request a directory rather than an individual file.

 

Trailing Slash Redirection

If you request a directory without including the trailing slash in its name (i.e. http://example.com/dir rather than http://example.com/dir/), then Apache must send a redirect to add the trailing slash to the URL. This is necessary so relative hyperlinks will work in the resulting file.

For this to work, Apache must know the name of the server so that it can send a redirect back to itself. Normally, when UseCanonicalName is set off, the name supplied by the client in the Host HTTP request header is used. If UseCanonicalName is on, then you need to assure that ServerName is set correctly in order for this redirect to work.

 

Directory Indexes

When a directory is requested, Apache may be configured to send a particular file within that directory automatically. This is configured with the DirectoryIndex directive. It can list one or more files that Apache should search for in the directory, with the first existing file being returned to the client. For example:

DirectoryIndex index.html index.htm index.php welcome.html

 

Directory Listings

If no file from the DirectoryIndex directive can be located in the directory, then mod_autoindex can generate a listing of the directory contents. This is turned on and off using the Options directive. For example, to turn on directory listings for a particular directory, you can use:

<Directory /usr/local/apache2/htdocs/listme>
  Options +Indexes
</Directory>

To prevent directory listings (for security purposes, for example), you should remove the Indexes keyword from every Options directive in your configuration file. Or to prevent them only for a single directory, you can use:

<Directory /usr/local/apache2/htdocs/dontlistme>
  Options -Indexes
</Directory>

 

Excluding Files

If you would like listings to be enabled, but you want to omit particular files, you can use the IndexIgnore directive. For example, to omit any filename starting with tmp and also the parent directory link (..), you could use:

IndexIgnore tmp* ..

 

Some files aren't listed

When a directory listing is produced, certain files will not be shown, by default. Files and directories that have access restrictions placed on them, either by password or by address, will not be shown in a directory listing.

If you want these files to be listed, you will need to set IndexOptions ShowForbidden in the directory block in question. The ShowForbidden setting is only available in 2.2 and later.

 

Headers and Footers

The directives HeaderName and ReadmeName configure a file to be included, respectively, above and below the file listing. If no path is given, Apache will look for these files in the directory being listed. For example:

HeaderName header.html
ReadmeName footer.html

A path starting in slash can be used if you want the same files included for all directories:

HeaderName /site/header.html
ReadmeName /site/footer.html

 

Styling the listing

The directory listing is highly configurable. The IndexOptions directive gives lots of choices for different configurations and the IndexStyleSheet directive allows a CSS stylesheet to be specified. A typical configuration might look like:

IndexOptions FancyIndexing HTMLTable
IndexStyleSheet /css/autoindex.css

 

Extended example

For a more complete example, including a configuration for the icons displayed with the files, see conf/extra/httpd-autoindex.conf as distributed with Apache httpd.

 

출처 : http://wiki.apache.org/httpd/DirectoryListings

반응형