Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable directory listing on apache; but access to individual files should be allowed

Tags:

I do not want to use .htaccess. How should I change my Directory attributes?

<VirtualHost *:80>    ServerName abc.com    DocumentRoot /usr/share/uploads    <Directory " /usr/share/uploads">       Order allow,deny       Allow from all    </Directory> </VirtualHost> 
like image 339
Deepak Singhal Avatar asked Jun 21 '12 11:06

Deepak Singhal


People also ask

Should I disable directory listing?

Another important security precaution is to disallow listing of files in directories. This can be set in the IIS (and should be already set as default configuration). It is recommended to disable directory listing for the whole website, although you can also disable this feature only for individual directories.

Which configuration directive can be used to disable directory listing on Apache server?

You can prevent directory listing for Apache by disabling mod_autoindex, setting appropriate options in the Apache configuration file, or by using . htaccess file.


2 Answers

If you are using Debian/Ubuntu, just go to terminal and type

sudo a2dismod autoindex sudo service apache2 restart 

If you are using Centos/Fedora, just do:

mv /etc/httpd/conf.d/autoindex.conf /etc/httpd/conf.d/autoindex.bkp /etc/init.d/httpd restart 

And similarly in other OS or distros...

This should disable the apache module that makes those fancy (normally useless and a security problem) directory listings. Also, as a bonus, you earn a bit of performance :-)

like image 168
Natxet Avatar answered Oct 05 '22 19:10

Natxet


I really couldnt find a direct answer on internet ; even on apache documentation. Finally, could find the solution through few iterations; we need to use Options and the value should NOT contain Indexes.

<Directory "/usr/share/uploads">         Options Includes FollowSymLinks MultiViews         AllowOverride None          Order allow,deny       Allow from all    </Directory> 
like image 36
Deepak Singhal Avatar answered Oct 05 '22 17:10

Deepak Singhal