I try to setup a virtual host besides the default localhost
.
Whenever I try to call my virtual host http://test
I get the default Apache2 Index file t
Maybe there is a problem with .conf files of the virtual-hosts.
First run the command:
apache2ctl -S
The response must be something like
VirtualHost configuration:
*:443 is a NameVirtualHost
default server localhost (/etc/apache2/sites-enabled/default-ssl.conf:2)
port 443 namevhost localhost (/etc/apache2/sites-enabled/default-ssl.conf:2)
port 443 namevhost myvhost.com (/etc/apache2/sites-enabled/myvhosts.com.conf:20)
alias www.myvhost.com
*:80 is a NameVirtualHost
default server localhost (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost localhost (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost myvhost.com (/etc/apache2/sites-enabled/myvhost.com.conf:1)
alias www.myvhost.com
But sometimes you can read:
default server myvhost.com (/etc/apache2/sites-enabled/default-ssl.conf:2)
so your vhost domain point to default configuration (http or https).
The solution is to add ServerName localhost
directive in the default-ssl.conf
and in the 000-default.conf
files.
Apache don't know who is the name of your default site and it takes one random resolving 127.0.0.1.
After setting the ServerName, you must run:
service apache2 reload
service apache2 restart
If you run again apache2ctl -S
you must see the correct match for the default server.