Reputation: 21
I have multiple A record for the same server IP address, I mean:
URL DNS res. goodurl.com 10.0.0.1 badurl1.com 10.0.0.1 badurl2.com 10.0.0.1
I would like to configure Apache2 so that it works only with URL goodurl.com and not with any other.
I've found the way to give "access denied" on specific URL "badurl1.com" like this :
<VirtualHost *:80>
ServerName badurl1.com
DocumentRoot /var/www
<Directory /var/www/>
AllowOverride None
Order deny,allow
deny from all
</Directory>
</VirtualHost>
Is there a more elegant and efficent way to do the same?
Is there a way to configure Apache to be sure that any other future and undesired new A record, will be rejected by default?
thanks in advance for your help
system SO: Linux 2.6.32-5-amd64 x86_64 GNU/Linux Server version: Apache/2.2.16 (Debian)
Upvotes: 0
Views: 3855
Reputation: 21
A friend suggested me to add this at the bottom of the config file. It works as I expected.
The trick is to create a (pseudo)random ServerName and to give an "*" as ServerAlias.
This way it matches my correct config for the ServerName and ServerAlias I've configured at the top and fallback on "fail" dir (with no access rights) for all other URLs poiting to my IP.
lupo@pippo:/var/www# mkdir fail
lupo@pippo:/var/www# chmod -R 000 fail
<VirtualHost *:80>
ServerName goodurl.com
ServerAlias www.goodurl.com goodurl
........
........
</VirtualHost>
<VirtualHost *:80>
ServerName lkfjLKJfiu90FJIDSNMFLKSDFMLKSDJNFLKSDFHIDOFH89DFY89NNS
ServerAlias *
DocumentRoot /var/www/fail
<Directory /var/www/fail/>
AllowOverride None
Order deny,allow
deny from all
</Directory>
</VirtualHost>
Upvotes: 2
Reputation: 4237
You should use dynamic virtual host. Essentially the path name will contain the virtual host server name, so that if the path does not exist, the server will return file not found.
<VirtualHost 111.22.33.44>
ServerName customer-1.example.com
DocumentRoot /www/hosts/customer-1.example.com/docs
ScriptAlias /cgi-bin/ /www/hosts/customer-1.example.com/cgi-bin
</VirtualHost>
<VirtualHost 111.22.33.44>
ServerName customer-2.example.com
DocumentRoot /www/hosts/customer-2.example.com/docs
ScriptAlias /cgi-bin/ /www/hosts/customer-2.example.com/cgi-bin
</VirtualHost>
<VirtualHost 111.22.33.44>
ServerName customer-N.example.com
DocumentRoot /www/hosts/customer-N.example.com/docs
ScriptAlias /cgi-bin/ /www/hosts/customer-N.example.com/cgi-bin
</VirtualHost>
becomes
# get the server name from the Host: header
UseCanonicalName Off
# this log format can be split per-virtual-host based on the first field
# using the split-logfile utility.
LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
CustomLog logs/access_log vcommon
# include the server name in the filenames used to satisfy requests
VirtualDocumentRoot /www/hosts/%0/docs
VirtualScriptAlias /www/hosts/%0/cgi-bin
http://httpd.apache.org/docs/current/vhosts/mass.html
Upvotes: 0