Apache2 virtualhosts

I’ve got a Novell exercise I’m busy doing where I need to setup an apache2 site called www. digitalairlines. com and 2 virtual sites hr.digitalairlines.com and marketing.digitalairlines.com

I’ve installed apache and got the www. digitalairlines. com going - easy enough with a index.html under /srv/www/htdocs - this works fine.

I then create a hr.conf and marketing.conf file under /etc/apache2/vhosts.d

hr.conf

<VirtualHost *:80>
    ServerAdmin webmaster@hr.digitalairlines.com
    ServerName hr.digitalairlines.com
    DocumentRoot /srv/www/vhosts/hr
    ErrorLog /var/log/apache2/hr.digitalairlines.com-error_log
    CustomLog /var/log/apache2/hr.digitalairlines.com-access_log combined

    HostnameLookups Off
    UseCanonicalName Off
    ServerSignature On

    ScriptAlias /cgi-bin/ "/srv/www/vhosts/hr/cgi-bin/"

    <Directory "/srv/www/vhosts/hr/cgi-bin">
        AllowOverride None
        Options +ExecCGI -Includes
        Order allow,deny
        Allow from all
    </Directory>

    <IfModule mod_userdir.c>
        UserDir public_html
        Include /etc/apache2/mod_userdir.conf
    </IfModule>

   <Directory "/srv/www/vhosts/hr">
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all

    </Directory>

</VirtualHost>

If I now got to hr.digitalairlines.com and marketing.digitalairlines.com the correct index.html is displayed. However if I go to www. digitalairlines. com I see the marketing web page displayed. Any ideas as to why this is occurring?

My default-server.conf file:

DocumentRoot "/srv/www/htdocs"
<Directory "/srv/www/htdocs">
        Options None
        AllowOverride None
        Order allow,deny
        Allow from all
</Directory>

Alias /icons/ "/usr/share/apache2/icons/"

<Directory "/usr/share/apache2/icons">
        Options Indexes MultiViews
        AllowOverride None
        Order allow,deny
        Allow from all
</Directory>

ScriptAlias /cgi-bin/ "/srv/www/cgi-bin/"
<Directory "/srv/www/cgi-bin">
        AllowOverride None
        Options +ExecCGI -Includes
        Order allow,deny
        Allow from all
</Directory>

<IfModule mod_userdir.c>
        UserDir public_html
        Include /etc/apache2/mod_userdir.conf
</IfModule>
Include /etc/apache2/conf.d/*.conf
Include /etc/apache2/conf.d/apache2-manual?conf

Please, post contents of marketing.conf as well.

Marketing.conf

<VirtualHost *:80>
    ServerAdmin webmaster@marketing.digitalairlines.com
    ServerName marketing.digitalairlines.com

    DocumentRoot /srv/www/vhosts/marketing

    ErrorLog /var/log/apache2/marketing.digitalairlines.com-error_log
    CustomLog /var/log/apache2/marketing.digitalairlines.com-access_log combined
    HostnameLookups Off

    UseCanonicalName Off
    ServerSignature On
    ScriptAlias /cgi-bin/ "/srv/www/vhosts/marketing/cgi-bin/"

    <Directory "/srv/www/vhosts/marketing/cgi-bin">
        AllowOverride None
        Options +ExecCGI -Includes
        Order allow,deny
        Allow from all
    </Directory>

    <IfModule mod_userdir.c>
        UserDir public_html
        Include /etc/apache2/mod_userdir.conf
    </IfModule>

    <Directory "/srv/www/vhosts/marketing">
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all

    </Directory>

</VirtualHost>

On 22/05/2012 10:16, gmccarthy wrote:

> I’ve got a Novell exercise I’m busy doing where I need to setup an
> apache2 site called www. digitalairlines. com and 2 virtual sites
> hr.digitalairlines.com and marketing.digitalairlines.com
>
> I’ve installed apache and got the www. digitalairlines. com going -
> easy enough with a index.html under /srv/www/htdocs - this works fine.
>
> I then create a hr.conf and marketing.conf file under
> /etc/apache2/vhosts.d
>
> hr.conf

…snip…

> If I now got to hr.digitalairlines.com and
> marketing.digitalairlines.com the correct index.html is displayed.
> However if I go to www. digitalairlines. com I see the marketing web
> page displayed. Any ideas as to why this is occurring?
>
> My default-server.conf file:

…snip…

Whilst you’ve created configuration files to set up virtual hosts for
hr.digitalairlines.com and marketing.digitalairlines.com you don’t
appear to have set up a virtual host for www.digitalairlines.com itself.

Since www.digitalairlines.com is not defined as a virtual host the first
defined virtual host is used as the default (though since h comes before
m in the alphabet I would expect hr.conf to be processed before
marketing.conf thus becoming the default).

See http://httpd.apache.org/docs/2.2/vhosts/name-based.html for more
information on name-based virtual hosts.

HTH.

Simon
Novell/SUSE/NetIQ Knowledge Partner