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.

My site is only loading with www.domain.com format not with domain.com. Any idea why? Here are my settings:

NameVirtualHost *:80

<VirtualHost *:80>
 ServerAdmin getintouch@domain.com
 ServerName domain.com
 ServerAlias domain.com www.domain.com
 DocumentRoot /var/www/domain.com/public_html/
 ErrorLog /var/www/domain.com/logs/error.log
</VirtualHost>

My DNS settings:

A/AAAA Records

 Hostname   IP Address          TTL 

            123.123.123.123     Default 
 www        123.123.123.123     Default 

Running Ubuntu on Apache2

share|improve this question
1  
You do not need to list domain.com in ServerAlias if it's already the ServerName. Other than that the config looks fine. What error do you get? Can you post the output of wget htto://domain.com and wget http://www.domain.com? Or, even better, reveal the domain name? –  zhenech Nov 3 '12 at 20:36
    
@zhenech When I type both in my browser domain.com is going to /var/www/ but www.domain.com is going to /var/www/domain.com/public_html/ for some reason. So they both work, just are directing traffic to the wrong folder. –  Alex Markov Nov 3 '12 at 20:42
    
You define DocumentRoot /var/www/domain.com/public_html/, so /var/www/domain.com/public_html/ is the correct folder and should work for both. Is this the only <VirtualHost> you have defined? –  zhenech Nov 3 '12 at 20:47
    
@zhenech This isn't the only one. I just made another one. I suppose things stopped working after I made that one. The other one is a subdomain of domain.com. It is the only <VirtualHost> in this file though. –  Alex Markov Nov 3 '12 at 21:02
    
What are the ServerName and ServerAlias lines of the other VirtualHost? Apache does not care if the hosts are in one or multiple files. –  zhenech Nov 3 '12 at 21:09
show 7 more comments

1 Answer

up vote 0 down vote accepted

The vhost to load first gets precedence - in this case, it's the one in /etc/apache2/sites-enabled/000-default. I'm assuming that the vhost you're intending to be active is the one in /etc/apache2/sites-enabled/domain.com, right?

Run a2dissite default, then restart Apache and you should be good!

share|improve this answer
    
This worked! Question: where is the vhost loading sequence defined? Default may be useful, is there a way to just put it last in order? Also, how some www.domain.com went before domain.com even though it was in the same <VirtualHost> ? –  Alex Markov Nov 3 '12 at 23:22
    
@AlexMarkov It's in load order - when a directory is included, then it's alphabetical, which is why the "default" file that comes in the package gets that 000 stuck in front of it. Now that you've disabled it, your domain.com file now acts as the default for hostnames that don't match one of the other virtual hosts. I'm guessing the reason that www.domain.com went to the right vhost is that it was not configured as a ServerAlias in the default file, so the default file wasn't overriding that name, just domain.com. –  Shane Madden Nov 3 '12 at 23:26
    
Got it! Thanks so much! –  Alex Markov Nov 3 '12 at 23:36
    
But the default host should never have matched in the first place, as it does not contain domain.com anywhere? –  zhenech Nov 4 '12 at 9:36
    
@zhenech Based on that apachectl -S output provided in the comments on the question, the vhost in the 000-default file had a ServerName of domain.com - so you were right on with the overlapping vhosts. –  Shane Madden Nov 4 '12 at 18:57
add comment

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.