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
For me it started to work after restarting apache with: sudo service apache2 reload. And pressing ctrl + F5 on http:/test.
I have seen this happen when using a fully qualified domain name (FQDN) in the /etc/hosts file that is the same as a site I was trying to connect to. To solve this problem I had to rename the FQDN to something other than one of my VirtualHost ServerName values.
So in other words, if my /etc/hostname was:
apple
And in my /etc/hosts, I had:
192.168.54.34 apple.example.com apple
And in my /etc/apache2/sites-enabled/apple.example.com.conf I had:
<VirtualHost *:80>
ServerAdmin blah@apple.example.com
ServerName apple.example.com
DocumentRoot /var/www/apple.example.com
DirectoryIndex index.html index.php
</VirtualHost>
apple.example.com would be accepted by the 000-default.conf because it is also listed in the /etc/hosts file. To solve this I just changed the FQDN of my server as follows in the /etc/hostname file:
server1
and /etc/hosts file:
192.168.54.34 server1.example.com server1
I was facing this issue, and it turned out I had to disable the default virtual host.
sudo a2dissite 000-default.conf
According to the apache documentation An In-Depth Discussion of Virtual Host Matching:
[...] If the main server has no ServerName at this point, then the hostname of the machine that httpd is running on is used instead.
That means if the default vhost (commonly 000-default.conf) has no ServerName set - which is the default - Apache will fallback to the hostname of the operating system.
As a result, Apache selects and serves from the default vhost (000-default.conf) even though another user-created vhost with the same ServerName as the machine's hostname is configured.
The reason is that Apache sorts the vhosts alphabetically by filename and chooses the first vhost configuration that matches the requested HTTP Host header. Thus, the 000-default.conf is checked before user-defined vhosts, as they are usually not prefixed with 000-
.
I ran through all of these solutions and none of them worked. Then, I decided to go back and check the apache2.conf file. I discovered that the line to include the "sites-enabled" conf files was commented out by default. By uncommenting the line and restarting apache, it fixed my problem (it was close to the end of the file):
# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf
This has bitten me more than once; sometimes I would enable with sudo
- sometimes I would not.
Ubuntu 14.04 seems to display the same message either way. When moving at 100 miles an hour, sometimes you miss a sudo
or two.
The symptom of the new website defaulting back to wrong directory has been my only clue the the enabling never happened. I'd say it's a bug.
It should at least warn when a command isn't executed!!!
if you keep default with *:80; *.443 make sure it is on the bottom - so rename 000-default to zzz-default