LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-22-2012, 09:26 AM   #1
gregmcc
Member
 
Registered: Mar 2007
Posts: 41

Rep: Reputation: 1
Apache2 virtual hosts confusion


I've got a exercise I'm busy doing on SLES/OpenSuse 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

Code:
<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>
marketing.conf
Code:
<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>
Default-server.conf
Code:
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
If I now go 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 hr web page displayed. Any ideas as to why this is occurring?

Last edited by gregmcc; 05-22-2012 at 09:28 AM.
 
Old 05-22-2012, 11:16 AM   #2
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
Hi,

in your "Default-server.conf"
define www
Code:
<VirtualHost *:80>
    ServerName www.digitalairlines.com
....
[/code]

because you don't have it, so the first "virtual" server page is served when you enter the domain "digitalairlines.com"
 
Old 05-22-2012, 01:39 PM   #3
gregmcc
Member
 
Registered: Mar 2007
Posts: 41

Original Poster
Rep: Reputation: 1
Thanks very much - that did the trick. I didnt know about the first virtual page being served.
 
Old 05-22-2012, 06:19 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,362

Rep: Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377
Use the ServerAlias directive https://httpd.apache.org/docs/2.2/mo...ml#serveralias instead.
The default should only be used if the user asks for a website you haven't defined anywhere else.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
apache2 virtual hosts dave`2005 Ubuntu 1 11-19-2007 07:17 AM
Virtual hosts on apache2 70mas Linux - Server 3 07-16-2007 02:29 AM
Apache2 Virtual Hosts Behind A Router serverjunkie Linux - Networking 2 10-28-2006 05:56 PM
Apache2 - need help with virtual hosts bioalchemist Linux - Software 5 08-11-2006 01:24 PM
apache2 virtual hosts viniosity Linux - Software 4 02-07-2004 12:15 AM


All times are GMT -5. The time now is 06:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration