Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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.

share|improve this answer
Updated question with reasons why that doesn't work – Lynden Shields Dec 4 '12 at 3:19
I don't see anything in your question that would cause this to not work. – Michael Hampton Dec 4 '12 at 3:21
I was worried I wasn't clear enough. Essentially when I do what you say, it serves all the files from all the sites. I need some of the sites to only serve specific files (actually they're django+relevant static files). The django parts should not be served, but are in their respective /var/www/ directories – Lynden Shields Dec 4 '12 at 3:24
@LyndenShields You have to use virtual hosts for that sort of separation. There is no way around it. Go buy a domain name. – Michael Hampton Dec 4 '12 at 4:11
Yes, but you can always use fake names, if this isn't going to be on the Internet. Otherwise... come on, a domain is less than $10 bucks. – Michael Hampton Dec 4 '12 at 4:21

Hard to tell what exactly you need, maybe you need to post httpd.conf?

Do you want the root URL to go to 404? Maybe try

RedirectMatch 404 ^/$

For the other part, this may help:

share|improve this answer
http2.conf is empty as per normal install of apache2 from ubuntu repos – Lynden Shields Dec 4 '12 at 4:16

I needed to replace the DirectoryRoot of Site 1's config with Alias /site1 /var/www/site1/

share|improve this answer

If you can change the IPTABLES setting:

iptables -I INPUT -d <server IP> -p tcp --dport 80 -m string --to 70 \
--algo bm --string 'GET / HTTP' -j DROP

This won't kill requests for /file but anything requesting the root directly at / will not be allowed access.

Alternatively you could make a couple allow rules for the pages you want to have working and one to block the root:

iptables -I INPUT -d <server IP> -p tcp --dport 80 -m string --to 70 \
--algo bm --string 'GET /' -j DROP
iptables -I INPUT -d <server IP> -p tcp --dport 80 -m string --to 70 \
--algo bm --string 'GET /site1' -j ACCEPT
iptables -I INPUT -d <server IP> -p tcp --dport 80 -m string --to 70 \
--algo bm --string 'GET /site2' -j ACCEPT
iptables -I INPUT -d <server IP> -p tcp --dport 80 -m string --to 70 \
--algo bm --string 'GET /site3' -j ACCEPT
share|improve this answer

Your Answer


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.