Disable Directory Listing in Apache – Apache Security

Introduction

In our previous article we discussed How To Install Linux, Apache, MySQL, PHP (LAMP) stack On CentOS 7. So, Securing your Apache web server is one of the most important task, specially when you setting up a new website. You can also see our previous posts for securing Apache by How to Disable Server Signature in Apache server.

If our website document directory does not have an index file(index.php/index.html), that time the Apache web server will show all the files and folder of the document root directory.

This is how directory listing will be shown to your visitors when index.html not present in it..

disable-directory-listing-in-apache

Disable Directory Listing in Apache

The best way to do disable directory listing and securing Apache by ‘options directive’ available in the Apache configuration file.

Edit Apache virtual host file.

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf               ## for centos/redhat
[root@localhost ~]# vim /etc/apache2/apache2.conf                ## for ubuntu/debian

Add following line into virtual host file

<Directory /var/www/html>
    Options -Indexes
</Directory>

Restart Apache

[root@localhost ~]# service httpd restart                        ## for centos/redhat
[root@localhost ~]# systemctl restart apache2                    ## for ubuntu/debian

Now Apache shows /index of look like this:

disable-directory-listing-in-apache

Avinash Pawar

DevOps Practitioner interested in learning new technologies and interested in sharing the knowledge with others.

More Posts - Website

Follow Me:
TwitterFacebookLinkedInGoogle Plus

Avinash Pawar

DevOps Practitioner interested in learning new technologies and interested in sharing the knowledge with others.

Leave a Reply