如何防止apache将服务器中的文件列表显示出来

来源:互联网 发布:大连淘宝 编辑:程序博客网 时间:2024/05/21 15:41

        1、環境:

                Apache_2.2.6

        2設置

當無法訪問到默認主頁的時候,Tomcat總會自動顯示文件的列表,解決的辦法如下:

        %apache%/conf/httpd.conf中,找到

<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs">

    #

    # Possible values for the Options directive are "None", "All",

    # or any combination of:

    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews

    #

    # Note that "MultiViews" must be named *explicitly* --- "Options All"

    # doesn't give it to you.

    #

    # The Options directive is both complicated and important.  Please see

    # http://httpd.apache.org/docs/2.2/mod/core.html#options

    # for more information.

    #

    Options Indexes FollowSymLinks

 

    #

    # AllowOverride controls what directives may be placed in .htaccess files.

    # It can be "All", "None", or any combination of the keywords:

    #   Options FileInfo AuthConfig Limit

    #

    AllowOverride None

 

    #

    # Controls who can get stuff from this server.

    #

    Order allow,deny

    Allow from all

 

</Directory>

将里面的Indexes去掉,然后重apache即可解決自動顯示文件列表問題。

雖然這樣子配置,將不會顯示文件列表,但是我們項目的文件夾中還是沒有指定Apache的默認主頁

%apache%/conf/httpd.conf中,找到

<IfModule dir_module>

    DirectoryIndex index.html

</IfModule>

index.html后面添加”index.php”文件来完成添加Apache默認主頁的設置

 

    注意,如果是在集群環境中,比如JBOSS+APACHE+JK,那么還需要在集群中的所有JBOOS中設置禁止文件列表,在%jboss%//server/all/deploy/jbossweb-tomcat55.sar/conf中,

    <init-param> 

              <param-name>listings</param-name> 

              <param-value>true</param-value> 

     </init-param> 

  true改为false就不会显示文件列表了。