10

I have added 2 virtual hosts to my apache2 conf file as below:

<VirtualHost *:80>
    DocumentRoot /var/www/html/site1
    ServerName www.site1.com
    ServerAlias site1.com
</VirtualHost>


<VirtualHost *:80>
    DocumentRoot /var/www/html/site2
    ServerName www.site2.com
    ServerAlias site2.com
</VirtualHost>

I then got the error after restarting apache i get:

[warn] default VirtualHost overlap on port 80, the first has precedence

Searched google and they said to uncomment the line below, so I did:

NameVirtualHost *:80

Restart, and now I don't get the error, but both sites go to the first site.

running Centos5. How do I fix this problem?

David
  • 841
  • 3
  • 14
  • 31

2 Answers2

14

You definitely want NameVirtualHost uncommented. That tells your server to server different virtual hosts based on the Doman Names used to reach it. That's why you see all requests go to the first site when it's removed.

Christopher Karel
  • 6,582
  • 1
  • 28
  • 34
  • 1
    Yea, I have done that and it still doesn't work. – David Dec 17 '09 at 14:04
  • Does it not properly serve up site2.com even with it? It really looks like your warning is just stating that your first VirtualHost is the default site for unmatched names. Which is essentially just how Virtual Hosts work. – Christopher Karel Dec 17 '09 at 14:08
  • 1
    After uncommented that line, i don't get a warning and both sites still go to site1 – David Dec 17 '09 at 14:25
  • Is it possible that your browser has just cached the content from site1 under site2's domain? Try clearing your cache or doing a proper refresh. (ctrl+F5) – Christopher Karel Dec 17 '09 at 16:07
1

I already fix this proble with CWP

just go to /usr/local/apache/conf/sharedip.conf

check this put * in your ip server

NameVirtualHost *:80
<VirtualHost *:80>
    ServerName yourdomainserver.ltd
    DocumentRoot /usr/local/apache/htdocs
    ServerAdmin root@youremail.com
    <IfModule mod_suphp.c>
        suPHP_UserGroup nobody nobody
    </IfModule>
</VirtualHost>
<Directory "/">
        AllowOverride All
        Allow from all
        Order Deny,Allow
</Directory>

then go to /usr/local/apache/conf.d/vhost.conf and be sure of each virtualhost looks like this

# vhost_start chango.com.ve
<VirtualHost *:80>
ServerName yourdomain.ltd
ServerAlias www.yourdomain.ltd
ServerAdmin youremail@yourdomain.ltd
DocumentRoot "/home/yourdomain/public_html"
ScriptAlias /cgi-bin/ "/home/yourdomain/public_html/cgi-bin/
# 
# Custom settings are loaded below this line (if any exist)
# Include "/usr/local/apache/conf/userdata/yourdomain/yourdomain.ltd/*.conf    
</VirtualHost>^M
# vhost_end yourdomain.ltd

this works for me!