0

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:

ports.conf

NameVirtualHost *:80
Listen 80
....

sites-available/default

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

sites-available/b

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

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

1 Answer 1

0

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.

3
  • 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
    Commented May 5, 2015 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 Commented May 6, 2015 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
    Commented May 6, 2015 at 12:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .