Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have to admin a web server with Apache 2 to deliver some different websites - every site has its own domain. The server has a single IP address, say: 78.9.10.11. For every site a VirtualHost is defined like this:

<VirtualHost *:80>
  ServerName mydomain.com
  ServerAlias *.mydomain.com
  ....
</VirtualHost>

It works fine, but there is a configuration problem: If someone tries to access the server via its IP address (http://78.9.10.11), the first VirtualHost is delivered - which I don't want. Instead, the access should be blocked or a special website should be served (to render some kind of error message). The server should only deliver sites by domain names.

How can I define a VirtualHost which is used for IP based access?

share|improve this question

migrated from stackoverflow.com Nov 29 '09 at 13:12

This question came from our site for professional and enthusiast programmers.

    
that behavior is By-Design and expected - if you've set global listening for the IP address –  warren Nov 29 '09 at 8:32

2 Answers 2

up vote 3 down vote accepted
<VirtualHost 78.9.10.11>
  ....
</VirtualHost>

Server up your custom error page (or whatever) inside that block.

share|improve this answer
    
Thanks, I have tried this before without success - but then I have recognized that my VirtualHost definition was not enabled... Argh! After doing an "a2ensite default" all works fine now. –  Georg Ledermann Nov 29 '09 at 14:58

Make sure the first VirtualHost that appears in your config file is like this

<VirtualHost *:80>
  ServerName not.configured
  DocumentRoot /var/www/notconfigured
  ...
</VirtualHost>

And then create an index.html in /var/www/notconfigured with the message you want

share|improve this answer

Your Answer

 
discard

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.