Enable directory browsing in apache

Source: Internet
Author: User

Apache enables directory browsing

Modify in the main configuration file httpd. conf:

1) add a support module.


LoadModule autoindex_module modules/mod_autoindex.so
LoadModule dir_module modules/mod_dir.so

Be sure to have these two modules. Otherwise, the following configuration does Not take effect and the error 404 Not Found is returned.
This module may also be directly compiled into the Apache core file httpd.

2) add Options Indexes to the DocumentRoot directory to generate a directory.

<Directory "/htdocs">
Options Indexes FollowSymLinks
</Directory>

Here, Indexes controls whether to enable directory browsing. To disable directory browsing, use

Option-Indexes

3) load httpd-autoindex.conf configuration

Include conf/extra/httpd-autoindex.conf


If you want to disable or, you can refer to the following section to disable the directory browsing function of Apache.


I. Default situation
By default, the configuration file/etc/httpd/conf/httpd. conf of Apache contains the following parameters:

Reference

Options Indexes FollowSymLinks
......

 

That is to say, there is no default homepage under the Directory (for example, index.html index. php, etc.), allows users to directly browse the web Directory Architecture, which may cause some important directories or configuration files to be published.

Generally, some security considerations are also made for Web applications. Taking Bo-Blog as an example, some directories contain similar files:

Reference
# Cat inc/index. php

Die ('Access Denied ');


In this way, you can avoid seeing the entire directory structure when you directly browse the directory. However, accessing the sub-directories below it does not work:
 
Therefore, this is still not safe.

II. Modify the configuration file
For security reasons, it is recommended that you disable the Indexes option in two ways:
1. Global shutdown
Modify the configuration file/etc/httpd/conf/httpd. conf mentioned above, and set:

Reference
Options Indexes FollowSymLinks


Changed:

Reference
Options-Indexes FollowSymLinks


Restart the httpd service to cancel the Indexes option of all websites.

2. Modify the. htaccess file
To disable this function for a specific website, enable. htaccess and modify/etc/httpd/conf/httpd. conf:

Reference

......
AllowOverride None
......

 

To:

Reference

......
AllowOverride All
......

 

Then, write a. htaccess file in the main directory of each website, with the following content:

Reference
# Head. htaccess
Options-Indexes


RewriteEngine on
RewriteBase/
......


It takes effect immediately after being saved.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.