LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (http://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Apache VirtualHost, multiple domains and subdomains (http://www.linuxquestions.org/questions/linux-networking-3/apache-virtualhost-multiple-domains-and-subdomains-215833/)

chrisfx 08-10-2004 12:32 PM

Apache VirtualHost, multiple domains and subdomains on one IP
 
Hi!

I'm having some problems to configure the httpd.conf with multiple domains and subdomains on one IP.
I'm able to run a single domain with its subdomains, but multiple domains with multiple subdomains always returns me the 1st website of the config file.
I've read the doc, but it always concern multiple hosts or subdomains, not the mixed case.

So, i'd like to run 2 internet domains (with their respectives subdomains):
- xxx.domain1.com (alias: domain1.com)
- sub1.domain1.com
- sub2.domain1.com
(no separated logs, everything logged under domain1.com)
and
- xxx.domain2.com (alias: domain2.com)
- foo.domain2.com
- bar.domain2.com
(no separated logs, everything logged under domain2.com)

and the primary will be a local domain:
- home
(own access and error logs)

Code:

NameVirtualHost *:80

<VirtualHost *:80>
  ServerName xxx.domain1.com
  ServerAlias domain1.com
  DocumentRoot /home/htdocs/domain1.com/
  CustomLog /home/htdocs/domain1.com/logs/domain1.com_access.log combined
  ErrorLog /home/htdocs/domain1.com/logs/domain1.com_error.log
</VirtualHost>

<VirtualHost *:80>
  ServerName sub1.domain1.com
  DocumentRoot /home/htdocs/domain1.com/sub1/
</VirtualHost>

<VirtualHost *:80>
  ServerName sub2.domain1.com
  DocumentRoot /home/htdocs/domain1.com/sub2/
</VirtualHost>


<VirtualHost *:80>
  ServerName xxx.domain2.com
  ServerAlias domain2.com
  DocumentRoot /home/htdocs/domain2.com/
  CustomLog /home/htdocs/domain2.com/logs/domain2.com_access.log combined
  ErrorLog /home/htdocs/domain2.com/logs/domain2.com_error.log

</VirtualHost>

<VirtualHost *:80>
  ServerName foo.domain2.com
  DocumentRoot /home/htdocs/domain2.com/foo/
</VirtualHost>

<VirtualHost *:80>
  ServerName bar.domain2.com
  DocumentRoot /home/htdocs/domain2.com/bar/
</VirtualHost>

and for the local site:

Code:

Port 80

ServerName home
ServerAdmin contact@home
DocumentRoot /home/htdocs/home


So when I try to reach xxx.domain2.com it always displays me xxx.domain1.com

UseCanonicalName and HostnameLookups are Off


any ideas?
thanks!

chrisfx


PS: as I'm new here and cannot post URLs containing "www" yet, i replaced "www" to "xxx" but it doesn't matter, just an ethetic point :P

Cedrik 08-10-2004 03:01 PM

Did you set the server IP for the ServerName directive ? also, dns resolve both www.domain2.com and www.domain1.com to your machine ?

chrisfx 08-10-2004 03:58 PM

Thanks for your quick reply,

Well, until today, I was running everything fine using only one domain name, domain1.com for example, without specifying any IP address somewhere in the config file.

Both domain1.com and domain2.com resolves to my public IP addr.

I'm behind a firewall (privave IP: 192.168.0.1), port 80 is routed to my machine (192.168.0.2).


All times are GMT -5. The time now is 04:00 AM.