Apache Multiple Domains + subdomains

Discussion in 'Server Operation' started by terbor, Jun 6, 2010.

  1. terbor

    terbor New Member

    Hi I am running into an issue with apache and setting up multiple domains on one server.

    Apache/2.2.12 (Ubuntu) Server 9.10
    bind9

    Issue:
    All traffic funnels to the first Virtual Host

    Setup:
    Bind:
    I setup 3 master zones asub.domain.com, domain.com, url.com (All traffic from these 3 are going to asub.domain.com, but if I delete asub the traffic will then go to domain.com)

    Apache:

    In sites-enabled
    domain.conf
    Code:
     <VirtualHost *>
       DocumentRoot /home/domain/asub
           ServerName asub.domain.com
           ServerAlias  www.asub.domain.com
           <Directory "/home/domain/asub">
           allow from all
           Options +Indexes
           </Directory>
     </VirtualHost>
    <VirtualHost *>
    DocumentRoot /home/domain/www
        ServerName domain.com
        ServerAlias  www.domain.com
         <Directory "/home/domain/www">
         allow from all
        Options +Indexes
        </Directory>
    </VirtualHost>
    url.conf
    Code:
    <VirtualHost *>
    DocumentRoot /home/url/www
        ServerName url.com
        ServerAlias  www.url.com
         <Directory "/home/url/www">
         allow from all
        Options +Indexes
        </Directory>
    </VirtualHost>
    Thank you for any help
     
  2. matty

    matty Member

    I'm a bit rusty on my Apache, but I'm pretty sure you need to name your VirtualHost, and put the wildcard/default entry last.

    ie.

    Code:
    <VirtualHost asub.domain.com>
       DocumentRoot /home/domain/asub
           ServerName asub.domain.com
           ServerAlias  www.asub.domain.com
           <Directory "/home/domain/asub">
           allow from all
           Options +Indexes
           </Directory>
     </VirtualHost>
    <VirtualHost domain.com>
    DocumentRoot /home/domain/www
        ServerName domain.com
        ServerAlias  www.domain.com
         <Directory "/home/domain/www">
         allow from all
        Options +Indexes
        </Directory>
    </VirtualHost>
    <VirtualHost *.domain.com>
    DocumentRoot /home/domain/www
        ServerName *.domain.com
         <Directory "/home/domain/www/promos">
         allow from all
        Options +Indexes
        </Directory>
    </VirtualHost>
    
    kind of thing. Apache reads the conf from top to bottom, so will match at the first chance, which the wild card does when it's at the top of the file.
     
  3. terbor

    terbor New Member

    Thanks for the reply, but I get an error when trying that ... I did see another post in here where the person used the * as I did here and it seemed to work for them ...

     
  4. matty

    matty Member

    Sorry, brain fart on my part. Getting old isn't much fun sometimes.. :rolleyes:

    I got my VirtualHost and NameVirtualHost bass-ackwards.

    Check you have an entry for NameVirtualHost, and that the server can resolve your DNS entries for your websites.

    What I should have done in the first place is refer you to the actual documentation. ;)

    http://httpd.apache.org/docs/2.2/vhosts/name-based.html
     
  5. terbor

    terbor New Member

    Thanks again for your help, I have been going back and forth between my old server and new server since I didnt move everything over yet I was changing where I was pointing the namservers for the same hostname and then apache would no longer honor the name setup that I had on the new server ... It works the way it should now ...
     

Share This Page