In Apache, how do I disable access to a website when someone only uses the IP address in a web browser?

Amr Elkhedewy asked:

I’m using apache web server on CentOS and I need to disable the ability for people to access the website by using the server’s IP address in a web browser. I want it so that when someone attempts to browse to the IP address they get a forbidden error message.

What configurations would be necessary to do that?

My answer:

Just set up the default virtual host. There is a commented example in httpd.conf or do something trivial like:

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot /var/www/html

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.