0

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:

/var/www/importer
/var/www/foostore

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

/etc/apache2/sites-available/default

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>
<Directory /var/www/importer>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>
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 127.0.0.0/255.0.0.0 ::1/128
</Directory>

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

127.0.0.1   localhost
127.0.1.1   VirtualHD
127.0.0.1   foostore
127.0.0.1   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.

3 Answers 3

2

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.

4

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.

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

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>

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

Then restart apache service apache2 restart

1
  • 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, 2012 at 8:18

You must log in to answer this question.

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