Apache2 + Disable Default Virtual Server

apache-2.2virtualization

This is the first time I actually try to setup a server myself.

Everything is working good so far. I have added a new virtual server and changed my domainĀ“s A records and it is now working as expected.

However: I would like to "block" access to the default www dir (in my case var/www). Right now when I enter the server IP instead of the domain, I get to the default www dir – I would like to disable that.

I dont want to setup a redirect, but simply forbid users, search engines etc. to view anything when they go to http://myip/

Currently I am doing the trick with adding an empty index.html, but I would like to actually block all requests and only allow access to my domains (they are in a subdir like "var/www/sites/domain.com/www")

I hope you get what I mean – my english sucks :/

p.s. since I installed webmin and I access it through http://myIp:webminPort – I think I actually only want to block port 80, but not sure about that…

Best Answer

You need to keep port 80 open as all your content for the domain.com/www vhost travels through 80 as well.

There is a default vhost setup by apache, you just need to comment it out in your httpd.conf.

To edit the config in webmin:

 Webmin -> Servers -> Apache Website -> Global Configuration

Give it a slow read through and you'll find the default vhost code block, just comment it out. This is worth it as you may want to tune settings later anyways.

Andre(OP) determined the default vhost definition was in /sites-enabled/default-000

Here is the section you are looking for:

### Section 2: 'Main' server configuration
#
# The directives in this section set up the values used by the 'main'
# server, which responds to any requests that aren't handled by a
# <VirtualHost> definition.  These values also provide defaults for
# any <VirtualHost> containers you may define later in the file.
#
# All of these directives may appear inside <VirtualHost> containers,
# in which case these default settings will be overridden for the
# virtual host being defined.
#

Comment out these Directives within Section 2 using a hash:

#ServerName
#<Directory />
#<Directory>
#---comment out all contents of this directory block---
#<Directory /var/www/html>
#---comment out all contents of this directory block---
#</Directory>
#DocumentRoot
Related Topic