Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've got a Ubuntu 10.04 LTS machine with a classical LAMP installed. I've created two sites:

A public site, on www.mysite.com

A "private" site that for the moment is open, on private.mysite.com

I've created two different config files for them,

/etc/apache/sites-available/mysite

/etc/apache/sites-available/private-mysite

With the default Apache virtualhost configs. No wildcards, the ServerName are www.mysite.com and private.mysite.com respectively, and I haven't used wildcards.

And of course there symlinks to those on /sites-enabled. Each of the sites has its own directory,

/var/www/mysite

/var/www/private-mysite

The public site is a WordPress blog. The private site is a webapp with several php files.

Everything should fine, and I've checked everything several times, but something weird happens. When I visit private.mysite.com the private part goes well.

But when I visit www.mysite.com, the server goes directly to private.mysite.com.

Apache logs show that those requests to www.mysite.com aren't even logged on

/var/www/mysite/logs/access.log (or error.log)

They go instead to

/var/www/private-mysite/logs/access.log

So EVERY request goes to the subdomain. Any ideas to correct this behaviour?

************** Update *******************

More info:

ls -l /etc/apache2/sites-available/

-rw-r--r-- 1 root root  859 2011-05-27 13:33 private-mysite
-rw-r--r-- 1 root root  948 2010-11-18 22:16 default
-rw-r--r-- 1 root root 7467 2010-11-18 22:16 default-ssl
-rw-r--r-- 1 root root  264 2011-05-27 14:22 mysite

/etc/apache2/sites-available/private-mysite contents:

<VirtualHost x.x.x.x:80>
     ServerName private.mysite.com
     DocumentRoot /var/www/private-mysite/html/
     ErrorLog /var/www/private-mysite/logs/error.log
     CustomLog /var/www/private-mysite/logs/access.log combined
</VirtualHost>

/etc/apache2/sites-available/mysite contents:

<VirtualHost x.x.x.x:80>
     ServerName www.mysite.com
     ServerAlias mysite.com
     DocumentRoot /var/www/mysite/
     ErrorLog /var/www/mysite/logs/error.log
     CustomLog /var/www/mysite/logs/access.log combined
</VirtualHost>
share|improve this question
    
Can you post configs? My money's on the VirtualHost address declaration not matching the NameVirtualHost block. And it may be a good idea to accept some answers to your older questions. –  Shane Madden May 27 '11 at 15:11
    
Edited, added info in case it is useful... –  javipas May 27 '11 at 18:38
    
Thanks for your answer, Shane, it was the solution!. I've reviewed my older questions, but there were not very valid answers to them. Should I accept answers even if they don't solve the problem?? –  javipas May 27 '11 at 19:27
    
No, but if they lead you in the right direction, then they may be good enough to accept. Another option is if your figure out a solution yourself, you can put your own answer in and accept it; this is good because future visitors may have the same issue and find your question in a search. –  Shane Madden May 28 '11 at 0:27
    
I'll review my questions and try to apply that criteria. Thanks for the tip Shane :) –  javipas May 28 '11 at 8:39

2 Answers 2

up vote 1 down vote accepted

The VirtualHost host definition blocks need to match the NameVirtualHost directive. It's probably in /etc/apache2/ports.conf, and is probably set to *:80.

To resolve, either change your NameVirtualHost:

NameVirtualHost x.x.x.x:80

or change your VirtualHost definitions:

<VirtualHost *:80>
share|improve this answer
    
That was EXACTLY the problem. Thank you so much!! –  javipas May 27 '11 at 19:24

Please post the configuration files themselves and ls -l /etc/apache/sites-available. Do you see any errors or warnings whatsoever when restarting Apache?

This may happen because www.mysite.com is not matching for some reason, and so Apache uses private.mysite.com as the default virtual host (as it's the only one present).

share|improve this answer
    
Info posted. Hope that helps! –  javipas May 27 '11 at 18:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.