Apache using incorrect default virtual host
system: ubuntu 14.04 as a VPS, apache 2.4.7
I have several virtual hosts set up, listening to :80 and :443 ports.
If I apache2ctl -S
it shows incorrect virtual host as default on port 80. And indeed, if I browse to http://default.com, I get the content from another virtual host: the one Apache points as the default, but shouldn't be (customer.com). What is wrong in my setup?
My enabled-sites are :
default.com customer.com
apache2ctl -S
VirtualHost configuration:
*:80 is a NameVirtualHost
default server customer.com (/etc/apache2/sites-enabled/customer.com.conf:1)
port 80 namevhost customer.com (/etc/apache2/sites-enabled/customer.com.conf:1)
port 80 namevhost www.customer.com (/etc/apache2/sites-enabled/customer.com.conf:19)
port 80 namevhost www.default.com (/etc/apache2/sites-enabled/default.com.conf:36)
port 80 namevhost tools.default.com (/etc/apache2/sites-enabled/default.com.conf:41)
port 80 namevhost phpmyadmin.default.com (/etc/apache2/sites-enabled/default.com.conf:57)
*:443 is a NameVirtualHost
default server default.com (/etc/apache2/sites-enabled/customer.com.conf:26)
port 443 namevhost default.com (/etc/apache2/sites-enabled/customer.com.conf:26)
port 443 namevhost default.com (/etc/apache2/sites-enabled/default.com.conf:1)
port 443 namevhost www.default.com (/etc/apache2/sites-enabled/default.com.conf:31)
port 443 namevhost default.com (/etc/apache2/sites-enabled/default.conf:26)
default.com Vhost
<VirtualHost *:443>
ServerName default.com
DocumentRoot /data/www/default.com/public
<Directory /data/www/default.com/public>
Require all granted
</Directory>
# SSL stuff ...
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/data/www/default.com/public/$1
</VirtualHost>
<VirtualHost *:443>
ServerName www.default.com
RedirectMatch (.*) https://default.com$1
</VirtualHost>
<VirtualHost *:80>
ServerName www.default.com
RedirectMatch (.*) https://default.com$1
</VirtualHost>
<VirtualHost *:80>
ServerName tools.default.com
DocumentRoot /data/www/default.com/subdomains/tools/public
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/data/www/default.com/subdomains/tools/public/$1
<Directory /data/www/default.com/subdomains/tools/public>
Require all granted
</Directory>
LogLevel error
</VirtualHost>
<VirtualHost *:80>
ServerName phpmyadmin.default.com
DocumentRoot /usr/share/phpmyadmin
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/usr/share/phpmyadmin/$1
<Directory /usr/share/phpmyadmin>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Customer.com vhost
<VirtualHost *:80>
ServerName customer.com
DocumentRoot /data/www/customer.com/public
<Directory /data/www/customer.com/public>
Require all granted
</Directory>
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9001/data/www/customer.com/public/$1
</VirtualHost>
<VirtualHost *:80>
ServerName www.customer.com
RedirectMatch (.*) http://customer.com$1
</VirtualHost>
Solution 1:
You don't have an entry for the non-www default.com
This should be added to the default.com config:
<VirtualHost *:80>
ServerName default.com
RedirectMatch (.*) https://default.com$1
</VirtualHost>