PDA

View Full Version : Apache Multiple Domains + subdomains


terbor
6th June 2010, 18:57
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
<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
<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

matty
7th June 2010, 02:52
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.


<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.

terbor
7th June 2010, 17:07
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 ...

* Restarting web server apache2
[Mon Jun 07 11:03:36 2010] [error] (EAI 2)Name or service not known: Could not resolve host name *.domain.com -- ignoring!
[Mon Jun 07 11:03:36 2010] [warn] VirtualHost modirac.com:80 overlaps with VirtualHost asub.domain.com:80, the first has precedence, perhaps you need a NameVirtualHost directive
... waiting [Mon Jun 07 11:03:58 2010] [error] (EAI 2)Name or service not known: Could not resolve host name *.domain.com -- ignoring!
[Mon Jun 07 11:03:58 2010] [warn] VirtualHost domain.com:80 overlaps with VirtualHost asub.domain.com:80, the first has precedence, perhaps you need a NameVirtualHost directive

matty
8th June 2010, 00:34
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

terbor
8th June 2010, 04:33
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 ...