The best way to disable directory browsing on Apache

The best way to do this is to disable it with webserver apache2. In Ubuntu open /etc/apache2/apache2.conf  in Centos, open /etc/httpd/conf/httpd.conf

change from

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

to

<Directory /var/www/>
        Options FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

then restart apache by:

sudo service apache2 reload
or 
systemctl reload httpd

This will disable directory listing from all folder that apache2 serves.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.