Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've enabled the 'www' subdomain host record that points to on my domain registrar's DNS editor a few days ago and the changes have propagated.

However I would like to temporarily disable it.

1) Why does work even though I've commented out the following code in /etc/apache2/sites-available/mysite?

#<VirtualHost *:80>
#DocumentRoot /mywebsite

Is it even needed to make changes in apache2 to enable the subdomain?

2) How can I temporarily disable the 'www' subdomain from apache2?

share|improve this question
Not knowing the rest of the contents in the apache config file, it's a little hard to answer :) – Mathias R. Jessen Mar 5 '12 at 23:12
I am not entirely sure what the effect of only specifying "ServerAlias" and not "ServerName", maybe its gets caught by another virtualhost section. – Tom H Mar 5 '12 at 23:17
up vote 3 down vote accepted

You may want to start by restarting apache to force reloading the apache config, to ensure its using the most recent directives;

service httpd restart <-- on centos or redhat
/etc/init.d/apache2 restart <--- on debian or ubuntu

If this is a live production site, you might also want to consider running a configuration check before applying the changes;

service httpd configtest <-- on centos or redhat
Syntax OK
/etc/init.d/apache2 configtest <--- on debian or ubuntu

if apache does not recognise the alias then it will get sent to the default site, either _default_:80 or *:80, depending on whether you have configured NameVirtualHost *:80

if you are on a sensible OS, then the apachectl command can be used to enumerate the virtualHosts that apache knows about like so;

[root@g0803 init.d]# apachectl -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80          is a NameVirtualHost  
default server (/etc/httpd/conf.d/boopo.conf:110)        
port 80 namevhost (/etc/httpd/conf.d/boopo.conf:110)     
     port 80 namevhost (/etc/httpd/conf.d/lime-portal.conf:5)   
_default_:443 (/etc/httpd/conf.d/ssl.conf:81)
Syntax OK

With HTTP 1.1 and name based virtual hosting, apache inspects the "Host" header in order to decide where to send the request, so unless you wish to switch the subdomain record over to some null destination, you are going to need to put in a VirtualHost to catch these requests with the www Host header, and redirect them to either a holding page, or to some dead end server.

A temporary work-around is to point your site to some empty folder, or back to the default home page e.g;

<VirtualHost *:80>
DocumentRoot /var/www/html
share|improve this answer
Thanks Tom, I'm using the temporary work around until the dns changes propagate. It seems if I comment out your work around, the default behavior is to set the alias to the document root of /mywebsite like you mentioned. – user784637 Mar 5 '12 at 23:26

Your Answer


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.