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 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: http://1.2.3.4/site1/ should work and serve the index from /var/www/site1/index.html, but http://1.2.3.4/ should not serve anything.

Currently, I can't get the url to point to the directory. Either I can get http://1.2.3.4/ to serve everything within /var/www/ (including /var/www/site2/secretstuff/), or I can get the root http://1.2.3.4/ 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 http://1.2.3.4/site1/* and not handle requests of the form http://1.2.3.4/

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

share|improve this question

4 Answers 4

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
1  
@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
1  
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:

http://httpd.apache.org/docs/2.2/urlmapping.html#documentroot

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

 
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.