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 have a website that I want to be able to reach using http://mydomain.com as well as http://www.mydomain.com

Recently I configured my servers hostname to mydomain.com

I have installed apache2 in default from ubuntu 12.04 repositories and configured the following configuration file under /etc/apache2/sites-enabled/mydomain.com

<VirtualHost *:80>
        ServerName mydomain.de
        ServerAlias     www.mydomain.de
        DocumentRoot /home/mydomain/public
</VirtualHost>
<Directory /home/mydomain/public>
        AllowOverride All
</Directory>

Now If I request http://www.mydomain.com everything works, but if I request http://www.mydomain.com I get the default "it works" apache welcome page.

If I prefix my config file in a way that it gets listed even before the 000-default vhost, so it looks like this:

ls -lha /etc/apache2/sites-enabled/
total 8.0K
drwxr-xr-x 2 root root 4.0K Jul  6 18:46 .
drwxr-xr-x 7 root root 4.0K Oct  5  2012 ..
lrwxrwxrwx 1 root root   33 Jul  6 18:45 000-0mydomain -> /home/mydomain/apache2.conf
lrwxrwxrwx 1 root root   26 Jul  6 18:29 000-default -> ../sites-available/default

it does work.

However I do not know whether this is a good idea or why this occurs in the first place. It also works when the server hostname does not correspond to the domain name!

I think apache is somehow unable to distinguish between requests without host header and requests whith the host header that is the same as the hostname...

So what can I do about this? How can I properly do this?

I think adjusting the name so my vhost ocmes eben before the default which is not named 000-default just to annoy people is not a good idea...

share|improve this question
    
Do you still need the default file enabled at all? –  Shane Madden Jul 6 '13 at 16:40
    
@Shane Madden no, i dont... not really... but i dont know about the future. i would like to set this up as clean and compatible as possible –  The Shurrican Jul 6 '13 at 16:54
add comment

1 Answer 1

When you type hostname -f, is that your domain as well? I think the default vhost is responding to the machine domain name. My advice would be to set a different host name for the machine, because the name you use to administer it should be different from the website that runs on it. Otherwise, you won't be able to do things like give the website a temporary different address and display a maintenance message.

If you don't want to do that, you can configure a dummy ServerName in 000-default.

share|improve this answer
    
yes, hostname -f is also that domain. i configured the machines hostname to the same domain for reasons when sending email. those problems i had have been completely solved and this new one arose. also modifying the default vhost is not really what i want. i prefer having all my stuff in one config file that i symlink and have in a versionized folder. –  The Shurrican Jul 6 '13 at 16:13
    
I mean, just having the 'it works' vhost's servername be www.dummy.com. That should fix it. –  Halfgaar Jul 6 '13 at 20:16
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.