# Apache 2 with virtual hosts and Dyndns



## Damonc (May 9, 2001)

Alright i'm stumped..

I have two domain names, and a dynamic IP address so I've subscribed to Dyndns.com which my router keeps up-to-date.

Anyways, problem is I've got a OpenSUSE 10.3 system running apache 2.2.4, which I have created two virtual hosts to catch each of the domain names.

I have the following in my config file.

```
<VirtualHost *>
ServerName www.domain1.com
ServerAlias domain1.com *.domain1.com
DocumentRoot /home/damon/public_html/domain1
DirectoryIndex index.php index.html index.htm
IndexOptions 
</VirtualHost>

<VirtualHost *>
ServerName www.domain2.net
ServerAlias domain2.net *.domain2.net
DocumentRoot /home/damon/public_html/domain2
DirectoryIndex index.php index.html index.htm
IndexOptions 
</VirtualHost>
```
Problem is that it doesn't matter if I enter in either domain1.com, domain2.net or my dyndns hostname I end up at the site for domain1.com

*domain1.com*
the DNS for this domain are hosted with dyndns and the A records point to my IP (which once again is automatically updated)

*domain2.net*
the DNS for this one are at afraid.org, im then using a CNAME record to forward it onto my dyndns hostname. so because of the way this one is setup, I would kinda expect domain2.net and the dyndns hostname to end up in the same spot.. but I would have thought it would have at least gone to the virtual host for domain2.net

All i'd like to achieve is different websites hosted on the same server, and the different domains linked to their respective websites.

Can anyone help me with this?

I'm guessing it may have something to do with the Dyndns service?

Oh - just an addition - if I use the servers LAN IP address to access the webserver, it connects me to the default servers page..


----------



## lotuseclat79 (Sep 12, 2003)

Hi DamonW,

Take a look at the Dyndns advisory Virtual Hosting With Apache to see if it helps. Looks like you do not have a "Listen" directive in either host setup.

I don't use Dyndns, so I'm just guessing in my comment above.

Suggest you search for other links on this problem: "Apache +Dyndns +virtual hosts"

-- Tom


----------



## Squashman (Apr 4, 2003)

I have never had any issues using NO-IP to do this.
Do you have this in your config file.

NameVirtualHost *


----------



## Damonc (May 9, 2001)

OK I was missing the NameVirtualServer * bit, so I've added that, and it still didnt work.. so I tweaked the virtual host config a tad..


```
<VirtualHost *>
ServerName www.domain1.com
ServerAlias domain1.com *.domain1.com
DocumentRoot /home/damon/public_html/domain1
DirectoryIndex index.php index.html index.htm
IndexOptions 
</VirtualHost>
```
is now


```
<VirtualHost domain1.com>
ServerName www.domain1.com
ServerAlias *.domain1.com
DocumentRoot /home/damon/public_html/domain1
DirectoryIndex index.php index.html index.htm
IndexOptions 
</VirtualHost>
```
so now I can access the correct page if I use http://domain1.com but if I put www.domain1.com I get the default server.. even tho I have the ServerAlias set to *.domain1.com... Unless someone can see a mistake that I've made there I can always just create a 2nd virtual server using the www bit so I can cover both bases.

and using http://domain1.com then once the page loads it shows http://www.domain1.com... strange.


----------



## tomdkat (May 6, 2006)

Slow down a bit. I believe:

NameVirtualHost *

<VirtualHost *>
ServerName www.domain1.com
ServerAlias domain1.com *.domain1.com
DocumentRoot /home/damon/public_html/domain1
DirectoryIndex index.php index.html index.htm
</VitrualHost>

<VirtualHost *>
ServerName www.domain2.com
ServerAlias domain2.com *.domain2.com
DocumentRoot /home/damon/public_html/domain1
DirectoryIndex index.php index.html index.htm
</VitrualHost>

is the syntax you want. Could you post all of the VirtualHost definitions you have, from NameVirtualHost down?

Peace...


----------



## Damonc (May 9, 2001)

Sure.. heres exactly what I've got.. (with the real domain names)


```
NameVirtualHost *
### Virtual server configuration ############################################
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs-2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
#Include /etc/apache2/vhosts.d/*.conf
<VirtualHost sausddesigns.com>
ServerName sausddesigns.com
ServerAlias *.sausddesigns.com
DocumentRoot /home/damon/public_html/wwwclients/sausddesigns
DirectoryIndex index.php index.html index.htm
IndexOptions 
</VirtualHost>

<VirtualHost www.sausddesigns.com>
ServerName www.sausddesigns.com
ServerAlias *.sausddesigns.com
DocumentRoot /home/damon/public_html/wwwclients/sausddesigns
DirectoryIndex index.php index.html index.htm
IndexOptions 
</VirtualHost>


<VirtualHost stolemy.net>
ServerName stolemy.net
ServerAlias *.stolemy.net
DocumentRoot /home/damon/public_html/wwwclients/stolemynet
DirectoryIndex index.php index.html index.htm
IndexOptions 
</VirtualHost>

<VirtualHost www.stolemy.net>
ServerName www.stolemy.net
ServerAlias *.stolemy.net
DocumentRoot /home/damon/public_html/wwwclients/stolemynet
DirectoryIndex index.php index.html index.htm
IndexOptions 
</VirtualHost>
```


----------



## tomdkat (May 6, 2006)

Thanks. Try changing ONE of the sites to be formatted like this:


```
<VirtualHost *>
ServerName sausddesigns.com
ServerAlias *.sausddesigns.com
DocumentRoot /home/damon/public_html/wwwclients/sausddesigns
DirectoryIndex index.php index.html index.htm
IndexOptions 
</VirtualHost>
```
You should also put a special index.html file in each DocumentRoot directory of each host so you can easily identify which VirtualHost definition is being used.

You won't need a VirtualHost definition for "www" subdomains. Also, if you use the "vhosts.d" directory, you can put each VirtualHost definition in its own config file, which keeps the main httpd.conf file from becoming HUGE. 

Peace...


----------



## Damonc (May 9, 2001)

yeah I did that thanks.... everything still ends up at the sausddesigns.com site..


----------



## tomdkat (May 6, 2006)

One thing I'm noticing is the IP addresses for one of your hosts, stolemy.net, doesn't seem to be right.

Check this out:

```
[email protected]:~$ dig sausddesigns.com

; <<>> DiG 9.5.0-P2 <<>> sausddesigns.com
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 19916
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;sausddesigns.com.		IN	A

;; ANSWER SECTION:
[b][color=red]sausddesigns.com.	60	IN	A	121.44.11.149[/color][/b]

;; Query time: 110 msec
;; SERVER: 192.168.2.1#53(192.168.2.1)
;; WHEN: Thu Feb 26 07:39:04 2009
;; MSG SIZE  rcvd: 50

[email protected]:~$ dig www.sausddesigns.com

; <<>> DiG 9.5.0-P2 <<>> www.sausddesigns.com
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52143
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;www.sausddesigns.com.		IN	A

;; ANSWER SECTION:
[b][color=red]www.sausddesigns.com.	43200	IN	CNAME	sausddesigns.com.
sausddesigns.com.	55	IN	A	121.44.11.149[/color][/b]

;; Query time: 112 msec
;; SERVER: 192.168.2.1#53(192.168.2.1)
;; WHEN: Thu Feb 26 07:39:09 2009
;; MSG SIZE  rcvd: 68

[email protected]:~$ dig stolemy.net

; <<>> DiG 9.5.0-P2 <<>> stolemy.net
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 64880
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;stolemy.net.			IN	A

;; ANSWER SECTION:
[b][color=red]stolemy.net.		2918	IN	A	67.19.72.202[/color][/b]

;; Query time: 50 msec
;; SERVER: 192.168.2.1#53(192.168.2.1)
;; WHEN: Thu Feb 26 07:39:32 2009
;; MSG SIZE  rcvd: 45

[email protected]:~$ dig www.stolemy.net

; <<>> DiG 9.5.0-P2 <<>> www.stolemy.net
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 49994
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;www.stolemy.net.		IN	A

;; ANSWER SECTION:
[b][color=red]www.stolemy.net.	3600	IN	CNAME	nep.dyndns.info.
nep.dyndns.info.	60	IN	A	121.44.11.149[/color][/b]

;; Query time: 167 msec
;; SERVER: 192.168.2.1#53(192.168.2.1)
;; WHEN: Thu Feb 26 07:39:36 2009
;; MSG SIZE  rcvd: 78
```
I don't know if the discrepancy in IP address for the stolemy.net domain will cause the behavior you described above or not.

Peace...


----------



## Damonc (May 9, 2001)

Well its still ending up at my server.. 

the stolemy.net domains name servers are different, its pointing to afraid.org which then points to dyndns then to me - long way around I know but its free, where I paid for sausddesigns.com to use the dyndns name servers.


----------

