Issue
I’m setting a new server on Debian 9, but this time I’m struggling with the vhosts.
Basically, the vhosts never reach their DocumentRoot, but fallback on the default DocumentRoot (/var/www/html
). As this is usually a simple matter of finding the right configuration, this time I don’t get it to work.
I reduced the conf files to the strict minimum to work on the problem. Let’s take 2 vhosts conf examples:
<VirtualHost 127.0.0.1:80>
ServerName www.site1.com
ServerAlias www.site1.com
ServerAdmin [email protected]
DocumentRoot /var/www/site1
</VirtualHost>
<VirtualHost 127.0.0.1:80>
ServerName www.site2.com
ServerAlias www.site2.com
ServerAdmin [email protected]
DocumentRoot /var/www/site2
</VirtualHost>
In this case, going either on www.site1.com
or www.site2.com
will fall to the default page on /var/www/html
.
If I’m changing one of the 120.0.0.1:80
to *:80
, it is immediately set as the working vhost. But if I set both on *:80
, it will fall on the first in the list.
Meaning if I have this:
<VirtualHost 127.0.0.1:80>
ServerName www.site1.com
ServerAlias www.site1.com
ServerAdmin [email protected]
DocumentRoot /var/www/site1
</VirtualHost>
<VirtualHost *:80>
ServerName www.site2.com
ServerAlias www.site2.com
ServerAdmin [email protected]
DocumentRoot /var/www/site2
</VirtualHost>
www.site1.com
and www.site2.com
will lead to /var/www/site2
. Same the other way.
But if I do this :
<VirtualHost *:80>
ServerName www.site1.com
ServerAlias www.site1.com
ServerAdmin [email protected]
DocumentRoot /var/www/site1
</VirtualHost>
<VirtualHost *:80>
ServerName www.site2.com
ServerAlias www.site2.com
ServerAdmin [email protected]
DocumentRoot /var/www/site2
</VirtualHost>
Then www.site1.com
and www.site2.com
will fall on www.site1.com
.
I triple checked my apache.conf
, ports.conf
. They’re both on the default settings after a fresh install.
All the usual answers on "solved" similar posts have been tried and checked:
apachectl -t
returns a Syntax OK
.
All conf files end with .conf
.
The chmod have been set to various tries, including 755, 775 and 777.
The matching user is set on the directories too.
I tried to sudo everything, restarting, reloading, etc.
I did reboot the server.
I’ve set the log on debug, but I can’f find everything wrong in it (though I’m not sure what to look for).
Just in case, here’s my /etc/hosts
:
127.0.0.1 localhost
127.0.1.1 sd-*****.dedibox.fr sd-****
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
and hostname:
sd-*****
I really don’t know what’s going on now. Thanks for any hint.
Solution
Okay, for some odd reasons I managed to get it to work with the second scheme, putting every vhost as *:80
.
Although it works, I have no clue about why my usual settings didn't work this time, nor about what I did to get it to work…
Answered By - EmmanuelBeziat