Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: [SOLVED] [apache2] virtual name-based hosting - defaults to wrong directory

  1. #1
    Join Date
    Sep 2008
    Beans
    6

    [SOLVED] [apache2] virtual name-based hosting - defaults to wrong directory

    Hello:

    I've been trying to set up my apache2 virtual name-based host.

    I have two domains:
    foo.com
    sub1.foo.com

    on different directories.

    Works great. But when I add a third one (sub2.foo.com) and enable it,

    sub2.foo.com works.

    but

    www.foo.com loads the home page for sub2.foo.com

    sub1.foo.com and foo.com load up properly.

    What I would like is to have www.foo.com load up the home page for foo.com, just like any regular website.

    Any ideas on how to fix this? Please tell me what config files you would like me to post and I'll put it up.

    Thanks very much for your help.


    Sincerely,

    yong_sa
    Last edited by yong_sa; September 12th, 2008 at 04:16 AM.

  2. #2
    Join Date
    Apr 2005
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: [apache2] virtual name-based hosting - defaults to wrong directory

    You may want to look up the Serveralias directive and have something like:
    ServerName www.foo.com
    ServerAlias foo.com

    Perhaps you have serveralias of *.foo.com somewhere?

    post the output of:
    Code:
    grep -i documentroot /etc/apache2/sites-available/*
    and
    Code:
    grep -i servername /etc/apache2/sites-available/*
    and
    Code:
    grep -i serveralias /etc/apache2/sites-available/*

  3. #3
    Join Date
    Sep 2008
    Beans
    6

    Re: [apache2] virtual name-based hosting - defaults to wrong directory

    Thanks! Here's what I have.

    Code:
    blah@mycomputer:~$ grep -i documentroot /etc/apache2/sites-available/*
    /etc/apache2/sites-available/default_old:       DocumentRoot /var/www/
    /etc/apache2/sites-available/sub2.foo.com:DocumentRoot /var/sub2.foo.com
    /etc/apache2/sites-available/foo.com:DocumentRoot /var/www
    /etc/apache2/sites-available/sub1.foo.com:DocumentRoot /var/sub1.foo.com
    
    
    blah@mycomputer:~$ grep -i servername /etc/apache2/sites-available/*
    /etc/apache2/sites-available/sub2.foo.com:ServerName sub2.foo.com
    /etc/apache2/sites-available/foo.com:ServerName foo.com
    /etc/apache2/sites-available/sub1.foo.com:ServerName sub1.foo.com
    
    blah@mycomputer:~$ grep -i serveralias /etc/apache2/sites-available/*
    /etc/apache2/sites-available/sub2.foo.com:ServerAlias http://sub2.foo.com
    /etc/apache2/sites-available/foo.com:ServerAlias www.foo.com
    /etc/apache2/sites-available/sub1.foo.com:ServerAlias http://sub1.foo.com

  4. #4
    Join Date
    May 2007
    Location
    Phoenix, Arizona USA
    Beans
    2,909
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: [apache2] virtual name-based hosting - defaults to wrong directory

    You need to disable the default site :

    Code:
    sudo a2dissite default
    Don't forget to enable each of your vhosts and then restart Apache:

    Code:
    sudo /etc/init.d/apache2 reload
    -Tim
    www.pcchopshop.net

    Hard to find and obsolete PC and server parts. "If we can't find it, it probably doesn't exist"

  5. #5
    Join Date
    Sep 2008
    Beans
    6

    Re: [apache2] virtual name-based hosting - defaults to wrong directory

    The default site is disabled (ie. no links in the sites-enabled directory). Do I need to delete the default_old file in the sites-available directory?

  6. #6
    Join Date
    May 2007
    Location
    Phoenix, Arizona USA
    Beans
    2,909
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: [apache2] virtual name-based hosting - defaults to wrong directory

    Well I don't think that's the problem but it certainly couldnt hurt.

    Can you post your apache2.conf and your sites-available file(s)?

    -Tim
    www.pcchopshop.net

    Hard to find and obsolete PC and server parts. "If we can't find it, it probably doesn't exist"

  7. #7
    Join Date
    Apr 2005
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: [apache2] virtual name-based hosting - defaults to wrong directory

    i'd probably try dropping the http:// in the serveralias directive.

  8. #8
    Join Date
    May 2007
    Location
    NY's first capital
    Beans
    2,661
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: [apache2] virtual name-based hosting - defaults to wrong directory

    I believe it is related to the "on address" directive. I did not know what the syntax meant in the default config file.

    I found it easier to use webmin and select 'default', or 'any' for the "on address directive".

    If I specified an ip or tried the <ServerName *> directive in the config file I would get overlap errors on apache restart. I would also have the wrong site load.
    Nothing is ever easy, but if it is difficult you must be doing it wrong.

  9. #9
    Join Date
    Apr 2007
    Beans
    468
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: [apache2] virtual name-based hosting - defaults to wrong directory

    Quote Originally Posted by mbeach View Post
    i'd probably try dropping the http:// in the serveralias directive.
    yes get rid of the http:// in the serveralias.

  10. #10
    Join Date
    Sep 2008
    Beans
    6

    Re: [apache2] virtual name-based hosting - defaults to wrong directory

    Dropping the http:// in the server alias worked! Thanks so much for your help! Now the web server passes the wife test! woohoo! Now she can get into the world of blogging.

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •