0

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.

4 Answers 4

3

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.

20
  • Updated question with reasons why that doesn't work Dec 4, 2012 at 3:19
  • I don't see anything in your question that would cause this to not work. Dec 4, 2012 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 Dec 4, 2012 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. Dec 4, 2012 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. Dec 4, 2012 at 4:21
0

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

1
  • http2.conf is empty as per normal install of apache2 from ubuntu repos Dec 4, 2012 at 4:16
0

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

0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .