I am currently trying to setup an virtual hosts following this tutorial on DigitalOcean.
The dummy-site I am trying to serve is under /var/www/example/html/index.html
. I have not registered an official domain but setup /etc/hosts/
to resolve example.com to the IP address of my server.
I created another conf file called example.conf
under /etc/apache2/sites-available
and enabled it with sudo a2ensite example.conf
and disabled the 000-default.conf
.
Now whenever I go to example.com
in my browser I get served:
This is the same page I would get when directly going to the IP address of my server. Only when I got directly to example.com/example/html
I get served the correct index.html
.
My current config looks like this:
<VirtualHost *:80>
ServerAdmin admin@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And my /etc/hosts
file on my laptop like this:
#<ip-address> <hostname.domain.org> <hostname>
<server-ip> example.com
There are some other folders inside /var/www/
as the company I rented the server from had some maintenance sites preinstalled, but that shouldn't matter in this situation. (See edit, this did actually matter).
It feels like I am missing something obvious here, but I can't find a solution for my problem.
Edit:
The obvious thing I was missing, was that 2 additional sites where enabled by default as well. One had the following contents:
# 10_froxlor_ipandport_<ip-address>.conf
# Created 28.11.2019 21:05
# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.
<VirtualHost <ip-address>:80>
DocumentRoot "/var/www/"
ServerName <predefined Server name>
</VirtualHost>
After disabling all the other sites, the request to example.com
actually went to the right index.html
.
I figure, that the above enabled site actually matched the request coming from my browser and showed the www
root directory.
The obvious thing I was missing, was that 2 additional sites where enabled by default as well. One had the following contents:
# 10_froxlor_ipandport_<ip-address>.conf
# Created 28.11.2019 21:05
# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.
<VirtualHost <ip-address>:80>
DocumentRoot "/var/www/"
ServerName <predefined Server name>
</VirtualHost>
After disabling all the other sites, the request to example.com
actually went to the right index.html
.
I figure, that the above enabled site actually matched the request coming from my browser and showed the www
root directory.