I'm trying to configure Apache2 to host different sections of my website for varying host names of the URL using name based virtual hosts.

My server is running Debian 7 with Apache version 2.2.22.

For example:

  • "example.com" and "a.example.com" will have the root directory /var/www/a/ (and is the default site)
  • "b.example.com" will have the root directory /var/www/b/

Below shows the edits I've made to the configuration files of Apache:


NameVirtualHost *:80
Listen 80


<VirtualHost *:80>
    ServerName a.example.com
    DocumentRoot /var/www/a/


<VirtualHost *:80>
    ServerName b.example.com
    DocumentRoot /var/www/b/

I've run "a2ensite b" and "service apache2 reload".

The index page of the the b site can be loaded becasue when I switch the document roots around, as in set the default side to /var/www/b/, I get the index page of site b when I go to (what would be) a.example.com.

The site is also definitely enabled as I can see the shortcut to the config file of b in the "sites-enabled/" folder


Have you checked, that you actually have symlink in sites-enabled folder? Sounds really like a problem that your sites-available/b config file is not loaded.

  • Last line: "The site is also definitely enabled as I can see the shortcut to the config file of b in the "sites-enabled/" folder". There's definitely a symlink there. – hojkoff May 5 '15 at 15:29
  • Have you tried moving ports.conf content into default conf? Maybe ports.conf is not loaded and thus Apache does not enable NameVirtualHost *:80 – Maksim Luzik May 6 '15 at 6:56
  • Tried that, no luck either. ports.conf does seem to be loaded by the global config file. If I add NameVirtualHost *:80 to the bottom if gives me a warning when I reload apache2 that there are two NameVirtualHost directives so it seems to be being loaded from ports.conf – hojkoff May 6 '15 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.