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'm new to Linux world and I'm getting stuck with the Apache version 2.2 Virtual host configuration.

In my local /var/www I have 2 sites (and the default localhost) in their respective directories:


Importer is an importer for a Opencart installed into daxstore directory, which I'm developing. I want two distinct sites working so I've copied the file


into the same directory two times, renaming it into "importer" and "foostore" and then edited them to:

<VirtualHost importer:80>
ServerAdmin webmaster@localhost

ServerName  importer
DocumentRoot /var/www/importer/
<Directory />
    Options FollowSymLinks
    AllowOverride None
<Directory /var/www/importer>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel debug
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from ::1/128

switching the name for the other side. I then edited /etc/hosts as follows:   localhost   VirtualHD   foostore   importer

Then I give the commands:

sudo a2ensite importer
sudo a2ensite foostore
sudo service apache2 restart

and apache goes right. When I try to access both sites, the browser redirect me on the foostore site (which also can't find some files but this is a matter for another question). Where am I wrong?

Thank you sirs.

share|improve this question
up vote 2 down vote accepted

Change the <VirtualHost> blocks of both site configurations from <VirtualHost importer:80> to <VirtualHost *:80> and make sure you have the correct ServerName directive in each file. Reload Apache.

If that doesn't help, check both access.log and error.log to get information about what Apache is actually doing.

share|improve this answer

First, make sure you have a NameVirtualHost *:80 line in your /etc/apache2/ports.conf file. Then try changing <VirtualHost importer:80> to <VirtualHost *:80> in your config.

share|improve this answer
obviously it is listening on port 80 if one of the sites loads – Christian Oct 13 '12 at 12:48
Right, that's the Listen directive's job. But if there's no NameVirtualHost directive, then name-based virtual hosts will not work properly. – Brian Showalter Oct 13 '12 at 20:15

First disable both the sites you just added using a2dissite site

Open up the default file and add the following to the top. Nice and simple. If you want to move them into their own conf file later or change security, you are welcome but test this first.

<VirtualHost *:80>
  ServerName importer
  DocumentRoot /var/www/importer

<VirtualHost *:80>
  ServerName foostore
  DocumentRoot /var/www/foostore

Then restart apache service apache2 restart

share|improve this answer
I can't add those section into the default site. It says: <VirtualHost> cannot occur within <VirtualHost> section Action 'configtest' failed. The Apache error log may have more information. Maybe I've misunderstood what you trying to tell me. – IssamTP Oct 14 '12 at 8:18

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.