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.