Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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! :)

share|improve this question
add comment

2 Answers

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.

share|improve this answer
    
Thanks, I'm checking into the config files to see if there are any overriding directives anywhere. –  stackdaemon Mar 28 '11 at 8:52
add comment

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".

share|improve this answer
    
Thanks, searching Directory Listing seems to have opened a few new doors. We'll se what surfaces. –  stackdaemon Mar 28 '11 at 8:52
    
No problem at all. –  Jonathan Ross Mar 28 '11 at 10:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.