1

I'm having trouble getting Apache to regonize an Options directive inside a VirtualHost block. The following snippet is as simple as I can make it that will reproduce the error - the rest of the configuration is a stock Deiban Apache 2.4.

<VirtualHost *:80> ServerName example DocumentRoot /home/test/ #owner www-data:www-data Options +Indexes <Location /> Require all granted </Location> </VirtualHost> 

This will fail with a 403 Forbidden and the following line in the corresponding log:

[Sun Jun 26 15:06:30.378689 2016] [autoindex:error] [pid 15899:tid 140693629712128] [client 192.168.0.155:52850] AH01276: Cannot serve directory /home/test/: No matching DirectoryIndex (index.html,index.cgi,index.pl,index.php,index.xhtml,index.htm) found, and server-generated directory index forbidden by Options directive 

However, placing the Options +Indexes directive inside the <Location /> container will fix it and the auto-generated index will be served.

I'd like to know why it must be placed inside <Location /> for it to work rather than just <VirtualHost>. The Apache 2.4 docs say that the Options directive can be placed in the following context[1]

Context: server config, virtual host, directory, .htaccess

So why is it not working inside VirtualHost?


Edit #1

Output of apachectl -S

AH00557: apache2: apr_sockaddr_info_get() failed for garnet AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message VirtualHost configuration: *:80 garnet.cat (/etc/apache2/sites-enabled/test.conf:1) ServerRoot: "/etc/apache2" Main DocumentRoot: "/var/www/html" Main ErrorLog: "/var/log/apache2/error.log" Mutex default: dir="/var/run/apache2/" mechanism=default Mutex watchdog-callback: using_defaults Mutex proxy: using_defaults PidFile: "/var/run/apache2/apache2.pid" Define: DUMP_VHOSTS Define: DUMP_RUN_CFG User: name="www-data" id=33 Group: name="www-data" id=33 

Regarding other possible Options directives somewhere else in config files:

I couldn't find any. I used root@garnet:/etc/apache2# grep -P -Rni '\soptions\s' . to find occurrences of the Options directive in the config files. All matches were in comment strings or in unrelated <Directory> blocks. Regardless, doesn't the VirtualHost block override directives specified outside it?

3
  • could it be some other config is overriding this? is this only vhost? what does apachectl -S say ? Commented Jun 26, 2016 at 15:53
  • There might be a global <Location /> directive somewhere in the config that has Options -Indexes in it. Commented Jun 26, 2016 at 15:59
  • I updated the question with new content relevant to your comments. Thanks! Commented Jun 26, 2016 at 16:48

1 Answer 1

0

This may well be a merging issue, details here: http://httpd.apache.org/docs/current/sections.html#merging

So in general the more specific configuration sections line Directory and Location location can override configuration at the Virtual Host level which in turn can override configuration at the global level. But when you get down to the more specific blocks of configuration, how they are handled in described in the link above.

These levels are called contexts in Apache terms and it is a really good idea to become familiar with what context means in this, er ... well ... context :-). More info here: http://httpd.apache.org/docs/current/mod/directive-dict.html#Context

As mentioned in the comments, look in the global context for Location, LocationMatch blocks that might match your URI path or Directory or DirectoryMatch that might match /home/test/ or anything above it in the directory tree.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.