# Can't bind two domains to one ip in virtual host



## sitao (Jun 19, 2010)

Installed apache22 & bind95 in Freebsd 8.  I want to bind two domains to one ip, but always fails.

Domain Resolving is ok, ping http://www.test.net or cn.test.net always connect to 60.160.130.40, and nslookup is ok.  But input two domains in browser, can't visit the webpage which should be specified, it always be navigate to the directory which DocumentRoot specified.  What's the matter?

I pasted the main content related, please help me to correct it.
/etc/named.conf part code followed: 


```
zone "test.net" in { 
       type master; 
       file "/var/named/etc/namedb/test.net"; 
       allow-update { none; }; 
}; 
zone "130.160.60.in-addr.arpa" in { 
       type master; 
       file "/var/named/etc/namedb/test.60.160.130"; 
       allow-update { none; }; 
};
```

/etc/namedb/test.net part code followed:


```
$TTL   86400 
$ORIGIN    test.net. 
@      IN     SOA    fbserver. root.test.net. ( 
                       23     ; 
                       12h    ; 
                       2h     ; 
                       3w     ; 
                       2h 
                       )      ; 

               IN     NS     fbserver. 
       3w     IN     MX     10     mail.test.net. 
email          IN     A      60.160.130.40 
mail           IN     A      60.160.130.40 
www            IN     A      60.160.130.40 
cn             IN     A      60.160.130.40 
test.ho        IN     A      60.160.130.40 
*
```
/etc/namedb/test.60.160.130 part code followed:

```
$TTL   86400 
$ORIGIN 130.164.61.IN-ADDR.ARPA. 
@      IN     SOA    fbserver. root.test.net. ( 
                       23     ; 
                       12h    ; 
                       2h     ; 
                       3w     ; 
                       2h     ; 
                       )      ; 

       IN     NS     fbserver. 
83     IN     PTR    email.test.net. 
83     IN     PTR    mail.test.net. 
83     IN     PTR    [url]www.test.net[/url]. 
83     IN     PTR    cn.test.net.
```
/usr/local/etc/apache22/httpd.conf part code followed:

```
ServerName 61.160.130.40:80 
DocumentRoot "/usr/data/www" 
NameVirtualHost 60.160.130.40 

<VirtualHost 61.160.130.40> 
    ServerAdmin [email]admin@test.com[/email] 
    DocumentRoot "/usr/data/www/test.net" 
    ServerName [url]www.test.net[/url] 
    ErrorLog "/var/log/test.net-error_log" 
    CustomLog "/var/log/test.net-access_log" common 
</VirtualHost> 

<VirtualHost 61.160.130.40> 
    ServerAdmin [email]admin@test.com[/email] 
    DocumentRoot "/usr/data/www/cn.test.net" 
    ServerName cn.test.net 
    ErrorLog "/var/log/cn.test.net-error_log" 
    CustomLog "/var/log/cn.test.net-access_log" common 
</VirtualHost>
```


----------



## hydra (Jun 19, 2010)

Try the reference configuration called "Running several name-based web sites on a single IP address". I think you may skip *ServerName* and *DocumentRoot* from the main configuration, since you only need virtual hosts. Have you changed the *Listen* parameter ?


----------



## sitao (Jun 19, 2010)

*Resolved.*

I replace the ip address with *, and then cancelled the ServerName and DocumentRoot parameters, and restart the apache service, and it's works.

Thank you very much.


----------

