3

I'm running Apache(2) on Debian. I want to disable automatic indexing in the /var/www dir and any subdirectories thereof.

In /etc/apache2/conf.d I put a file with the following contents:

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

I was under the impression that this directive would be applied recursively on any subdirs of /var/www, but accessing, say, /var/www/someotherdir (missing an index.html) gives me a listing of the directory contents even after restarting apache (apache2ctl restart).

Did I misunderstand the recursiveness here and need to use a .htaccess file?

Best regards! :)

Edit For the internet:

I went through my "main" or "root" config file, /etc/apache2/apache2.conf, and found the following include directives, in the following order:

include mods-enabled/*.load
include mods-enabled/*.conf
include httpd.conf
include ports.conf
include conf.d/
include sites-enabled/

Whereas most of the conf files did not hold any content that seemed relevant to /var/www listing options, the sites-enabled dir held a file named 000-default that in turn held a virtual host post, specifying some options for the /var/www dir. Like this:

<VirtualHost *:80>
<Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

Based on the directive merge order found at http://httpd.apache.org/docs/current/sections.html#mergin , it seems that my directive specification in conf.d/myfile for /var/www would be overridden by the sites-enabled/000-default directives on grounds of pointing to the same directory and the virtual host directives being processed last.

Removing the Indexes option from the sites-enabled/000-default file turned off directory listing in the /var/www subtree. So in that sense everything seems logical.

A slight point of confusion still exists, tho. If I include a directive for a specific directory in my conf.d/myfile file, say /var/www/exampledir, the exampledir will have its directory listing turned off regardless of the contents of the virtual host directives. As such, it would seem that a directive processed later will not override a more specific setting even though it was set earlier. I'll try to give an example:

In a sort of "pseduo config file syntax", let's say I have the following settings being included in the following order:

index off on /var/www (in my conf.d file)
index off on /var/www/exampledir (in my conf.d file)
index on in /var/www (in 000-default file)

Then it seems that /var/www will have "index on" in all subdirs except /var/www/exampledir, where the directive have been applied recursively. So it seems the recursive setting in the 000-default file will not affect the "index on" on an earlier, more specifically named dir.

OR, coming to think of it, it could mean that the config file directives are processed, as mentioned in the Apache docs link, from shortest to longest, but the virtual host directives will be processed last per specified dir and NOT after all other non-virtual-host-directives, regardless of length (which I sort of supposed until now).

Ah, yes, that would perhaps explain things. Well, if anyone read this far, grats to you and good luck to us both! :)

stackdaemon
  • 131
  • 1
  • 1
  • 4

2 Answers2

2

Your settings are right, that should work like you expected. Maybe you are overriding Options -Indexes somewhere deeper in your directory tree or in another vHost for example.

fab
  • 2,308
  • 2
  • 16
  • 14
0

There should be one command that rules all !

Depending on the OS then httpd.conf or another config file should just have "Options All FollowSymLinks MultiViews" instead of "Options All Indexes FollowSymLinks MultiViews".

I think maybe you're searching for the wrong terminology (it's tricky at best). It's referred to "Directory Listing" as opposed to "Indexing".

jscott
  • 24,204
  • 8
  • 77
  • 99
Jonathan Ross
  • 2,173
  • 11
  • 14