Apache 2.4 on Ubuntu Linux has directory listing enabled by default. In case you are upgrading from apache 2.2 or creating a new site, you may want to disable it. We’ll use Ubuntu linux for the purpose of this tutorial.
Directory listing example
To see directory listing on a new Apache default installation on Ubuntu linux follow these steps:
$ sudo mkdir /var/www/html/foo $ sudo touch /var/www/html/foo/file1.txt
Now hit the browser with url /foo. You should see something like this:
Disable directory listing
To disable directory listing add the following config lines to you custom Apache conf file:
<Directory /var/www/> Options -Indexes Options +FollowSymLinks AllowOverride None Require all granted </Directory>
Also make sure you config file is included in
/etc/apache2/apache2.conf. It is a good idea to keep your config changes in a separate config file. That way future upgrade won’t impact your config. After the change, restart apache. Here is how a directory url will look like in Chrome after this change:
Note that your config and directory location may be different from this example. You may need to follow the instructions appropriately.