Virtual Host on Top Level Domain not working

mburn asked:

I’m trying to route a top level domain through Apache Virtual Hosts, but I can’t seem to get it to work.

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName mydomain.net
    ServerAlias www.mydomain.net
    DocumentRoot /var/www/tgc
</VirtualHost>

www.mydomain.net works perfectly. But mydomain.net continues to route to /var/www. I’ve tried suggestions here and many different combinations, but nothing seems to work.

apachectl -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
     default server mydomain.net (/etc/apache2/sites-enabled/000-default:1)
     port 80 namevhost mydomain.net (/etc/apache2/sites-enabled/000-default:1)
     port 80 namevhost mydomain.net (/etc/apache2/sites-enabled/000-default:54)
Syntax OK

My answer:


You defined two virtual hosts for your domain, and so only one of them is used. Fix this by removing one of them.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.