Apache: Don’t deliver website by IP address

Posted on

Apache: Don’t deliver website by IP address – Managing your servers can streamline the performance of your team by allowing them to complete complex tasks faster. Plus, it can enable them to detect problems early on before they get out of hand and compromise your business. As a result, the risk of experiencing operational setbacks is drastically lower.

But the only way to make the most of your server management is to perform it correctly. And to help you do so, this article will share nine tips on improving your server management and fix some problem about apache-2.2, virtualhost, , , .

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: For every site a VirtualHost is defined like this:

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

It works fine, but there is a configuration problem: If someone tries to access the server via its IP address (, 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?

Solution :


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

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

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

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

Leave a Reply

Your email address will not be published. Required fields are marked *