Question

I try to set up virtual hosts on my server. I already add virtual host for my default domain:

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName domain.com
    ServerAlias www.domain.com
    DocumentRoot /srv/www/domain.com
</VirtualHost>

<Directory /srv/www/domain.com>
    Options +FollowSymLinks -Indexes
    AllowOverride All
    order allow,deny
    allow from all
</Directory>

Now domain.com and www.domain.com has document root /srv/www/domain.com

But www1.domain.com, www2.domain.com, ..., *.domain.com domains also have document root /srv/www/domain.com. How to deny access to server from all domains beside domain.com and www.domain.com?

Was it helpful?

Solution

I just need to add before virtual hosts:

ServerName localhost

<VirtualHost _default_:80>
    <Directory />
        deny from all
    </Directory>
</VirtualHost>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top