Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm running an apache-server, with a bunch of virtual hosts for about seven domain names. Now I'd like to disallow access for clients who try to access my server using only its IP-adress. So:

  • When someone accesses my website through, they reach the site hosted in /var/www/

  • When someone enters the ip-address of the server they reach a 403 Forbidden-message.

The problem with this is that they are theoretically able to reach my other sites through bruteforce, when getting

I rather want them to reach a 403 Forbidden all the time, as long as they don't access my server by a valid domain name.

How do I solve this problem?

share|improve this question
up vote 1 down vote accepted

With name-based virtual hosts, the first VirtualHost to load will get all requests that don't have a host name (or that have a host name that doesn't match one that's configured).

On Debian, what you likely have is a file /etc/apache2/sites-available/default that is loading first because its link is located at /etc/apache2/sites-enabled/0-default (first alphabetically means it will load first) which is set with a VirtualHost that serves up /var/www/.

Assuming that your is served by either a different site file, or a different VirtualHost block in the same file, one good solution would be to set the default VirtualHost to no longer serve up any documents at all, and to have it instead send a redirect over to the correct DNS name. This approach will also apply the same action to any request that comes in with a host header that your system doesn't recognize:

RewriteEngine on

RewriteRule ^.*$ [R]

share|improve this answer

Change the default document path to something else than /var/www/. For example set default path to /var/www/forbidden/.

You can also create _default_ virtual host, which will match everything that is not matched by other virtual hosts.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.