homepage Welcome to WebmasterWorld Guest from 54.197.171.109
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Blocking virtual hosts that don't exist
teokolo




msg:4550870
 10:25 am on Mar 4, 2013 (gmt 0)

Hello,
I'd like to block (or to show an error page) to every request for a domain not present in my apache vhost configuration.

I found some domains (not in my control) which resolve to my server ip address and I don't know how to block them.

For example:
mydomain.com : 1.1.1.1
externaldomain.com: 1.1.1.1

NameVirtualHost 1.1.1.1
<VirtualHost 1.1.1.1>
ServerName mydomain.com
...
</VirtualHost>
<VirtualHost 1.1.1.1>
ServerName mydomain2.com
...
</VirtualHost>


If you access externaldomain.com, apache shows the content of mydomain.com.

Thanks in advance.

Teo

 

phranque




msg:4552051
 10:19 am on Mar 7, 2013 (gmt 0)

i haven't tested it, but something like this in the httpd.conf file (after all the other more specific VirtualHost containers) should probably do the job to create a "catch-all":

<VirtualHost *:80>
ServerName _default_
ServerAlias *
DocumentRoot /usr/web/wildcard/htdocs

RewriteEngine on
RewriteRule ^ - [F]

</VirtualHost>



this should respond to any request (on port 80) for a non-specified hostname with a 403 Forbidden status code.

teokolo




msg:4552219
 5:42 pm on Mar 7, 2013 (gmt 0)

phranque thank you for your input, I solved the problem.

My server has 2 IP addresses and some domains on it.

The solution is adding a _default_ virtual host at the beginning, something like this:


NameVirtualHost 1.1.1.1
<VirtualHost 1.1.1.1>
ServerName _default_
DocumentRoot /var/www/html/blackhole
</VirtualHost>
<VirtualHost 1.1.1.1>
ServerName example.com
DocumentRoot /var/www/html/example.com
</VirtualHost>


NameVirtualHost 2.2.2.2
<VirtualHost 2.2.2.2>
ServerName _default_
DocumentRoot /var/www/html/blackhole
</VirtualHost>
<VirtualHost 2.2.2.2>
ServerName example2.com
DocumentRoot /var/www/html/example2.com
</VirtualHost>



You can check the configuration with apachectl -S

phranque




msg:4552255
 6:47 pm on Mar 7, 2013 (gmt 0)

that looks like a good solution.

what's the response when the request hits the blackhole?

teokolo




msg:4552465
 7:57 am on Mar 8, 2013 (gmt 0)

Right now I'm just showing the Apache test page, maybe "403 unauthorized" would make more sense.

phranque




msg:4552533
 11:50 am on Mar 8, 2013 (gmt 0)

you can do this in your .htaccess file, either using mod_access and a "Deny from all" directive or using mod_rewrite and the RewriteRule directive's F flag, similar to the example above.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved