How to set up Apache 2 to serve only subdirectories

Lynden Shields asked:

I have 3 sites which need to be hosted on a web server (apache2 from repo running on Ubuntu 12.04). They are each in their own subdirectory within /var/www/

I would like apache to serve files from the relevant directories only if the directory name is given in the URL, but not serve the /var/www/ directory itself.

E.g: should work and serve the index from /var/www/site1/index.html, but should not serve anything.

Currently, I can’t get the url to point to the directory. Either I can get to serve everything within /var/www/ (including /var/www/site2/secretstuff/), or I can get the root to serve one of the subdirectories (/var/www/site1/). This is unacceptable site 1 needs Indexes enabled but the others must not.

I just want to make site1’s config only respond to requests of the form* and not handle requests of the form

I do not have a domain name set up so I can’t use subdomains.

My answer:

Just go with the easy fix: put a blank index.html in /var/www:

touch /var/www/index.html

Going to the top level will then just result in a blank page.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.