How to prevent directory listing in apache2?

June 16, 2015 8.4k views

I would like to know how to prevent directory listings in Apache2 on debian7.
For example, I am able to view the contents of a folder called "test.php" that created inside /var/www. I don't want visitors to be able to view the contents of directories.

For the apache2.conf file , I have changed the

<Directory "/var/www">
Options Indexes FollowSymLinks
IndexOptions FancyIndexing FoldersFirst IgnoreCase VersionSort NameWidth=*


<Directory "/var/www">
Options FollowSymLinks

and set
<Directory /var/www/test>
Options -Indexes

It is no use to restart my apache2 ,the test.php file in the /var/www still be viewed by others when to input my vps_ip in firefox .

1 comment
  • I am not sure naming a folder with a .php extension is such a good idea, but to answer your question:

    sudo a2dismod autoindex
1 Answer

it works fine ,think you.

Have another answer? Share your knowledge.