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: 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?

Solution :

<VirtualHost 78.9.10.11>
  ....
</VirtualHost>

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
  ...
</VirtualHost>

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 *