2
127.0.0.1 developmentsite.com
127.0.0.1 blockeddomain1.com
127.0.0.1 blockeddomain2.com

I would like to block the last 2 domains (and a bunch of others). For this I have added the following vhost entry:

<VirtualHost *:80>
    DocumentRoot "/sites/blocked"
    <Directory /sites/blocked>
        Options Indexes FollowSymLinks Multiviews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

That works fine. But now I'd like the first domain to get routed to a site I'm serving (running XAMPP). This works for routing ALL the domains to my dev site:

<VirtualHost *:80>
    DocumentRoot "/sites/developmentsite.com"
    ServerName developmentsite.com
    ServerAlias developmentsite.com
    <Directory /sites/developmentsite.com>
        Options Indexes FollowSymLinks Multiviews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
    ErrorLog "/sites/logs/developmentsite.com/error_log"
    CustomLog "/sites/logs/developmentsite.com/access_log" common
</VirtualHost>

But I want to send just the developmentsite.com there. I've tried different ports and ips, but I think I just don't understand something basic.

Sorry to ask such a basic question. Thanks!

Saurabh Barjatiya
  • 4,643
  • 2
  • 29
  • 34
dylanized
  • 123
  • 4

2 Answers2

1

I think you need to look at virtual-host configurations again. Question does not make sense. How

<VirtualHost *:80>
    DocumentRoot "/sites/blocked"
    <Directory /sites/blocked>
        Options Indexes FollowSymLinks Multiviews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

allows developmentsite.com and blocks other sites is not clear when nothing about what to allow and what to block in mentioned in the configuration. Have a look at http://www.sbarjatiya.com/notes_wiki/index.php/Apache_virtualhost_configuration_for_hosting_multiple_domains to learn basics of Apache virtual-hosting. Then use

Order deny,allow
deny from all 

to deny domains that you do not want to be accessed.

Then use 'ProxyPass' to forward requests of one local site to other server, etc.

Saurabh Barjatiya
  • 4,643
  • 2
  • 29
  • 34
1

I think that your "blocking" VirtualHost is only working as you hope due to Apache's default behaviour; if it can't find a VirtualHost with a ServerName/ServerAlias matching the request, it will use the default VirtualHost (which, if not explicitly selected, is the first one it parses).

You should place the sites you want to explicitly block into your "blocking" VirtualHost, like so:

<VirtualHost *:80>
    # Add these lines so Apache knows explicitly what to route here:
    ServerName blocking.localhost
    ServerAlias blockeddomain1.com *.blockeddomain1.com
    ServerAlias blockeddomain2.com *.blockeddomain2.com

    # Everything else
    DocumentRoot "/sites/blocked"
    <Directory /sites/blocked>
        Options Indexes FollowSymLinks Multiviews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>
nickgrim
  • 4,336
  • 1
  • 17
  • 27