I am setting up an apache2 server with a number of virtualhosts.
They are all working except for www.mydomain.com, which goes to the default virtualhost instead of the virtualhost I created for it.
The virtualhost file (www.mydomain.com.conf) looks like this:
<VirtualHost *:80>
ServerName www.mydomain.com
ServerAdmin [email protected]
DocumentRoot /var/www/mydomain.com/www
ErrorDocument 404 "/error.php"
</VirtualHost>
If I change ServerName
to www2.mydomain.com
it works. If I change it back to www.mydomain.com
it goes to the default virtualhost.
The default virtual host file (000-default.conf) looks like this:
<Virtualhost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/mydomain.com/html
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/mydomain.com/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
LogLevel warn
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
One other thing to note, that may be affecting this, is that the hostname of the server (/etc/hostname) is www.mydomain.com
Is www.
a special case? Why is this happening and how do I make it work like I want it to?
I am using Ubuntu 16.04, Apache2 Server version: Apache/2.4.18 (Ubuntu)
EDIT: I have confirmed that the problem was /etc/hostname having www.mydomain.com - I changed it to www-server.mydomain.com and now the www virtualhost goes to the right place. I still don't know why this happens.