Score:0

Trying to make name-based virtual hosts work on apache2 with self hosted DNS

tz flag

I'm reading a book on Ubuntu Server and after wiring all the networking, DHCP, DNS, NTP and all, we got to the point where we need to create an apache2 web-server.

I followed all the instructions but when we got to the multiple virtual host part, I can't seem to make it work.

Having only one network interface, I opted for the named-based virtual hosts. I'm going to list all my DHCP, DNS and Apache2 configurations to make it easy for everyone to figure the problem out.

DHCP

/etc/dhcp/dhcpd.conf

default-lease-time 43200;
max-lease-time 86400;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
option domain-name "local.lan";
authoritative;
subnet 192.168.1.0 netmask 255.255.255.0 {
    range 192.168.1.100 192.168.1.240;
    option routers 192.168.1.1;
    option domain-name-servers 192.168.1.1;
}

DNS

/etc/bind/named.conf.options

options {
        forwarders {
          8.8.8.8;
          8.8.4.4;
        };
        dnssec-validation auto;
        listen-on-v6 { any; };
};

/etc/bind/named.conf.local

zone "local.lan" IN {
    type master;
    file "/etc/bind/net.local.lan";
};

/etc/bind/net.local.lan

$TTL 1D
@ IN SOA local.lan. exampleemail.local.lan. (

202212152; serial

8H ; refresh
4H ; retry
4W ; expire
1D ) ; minimum
IN A 192.168.1.1
;
@ IN NS lenovo.local.lan.
lenovo     IN  A   192.168.1.1 #my server

WEBSITE

For the website configuration, I created a file called 000-virtual-hosts.conf that holds the config for the virtual hosts I want to make work.

/etc/apache2/sites-available/000-virtual-hosts.conf

<VirtualHost *:80>
        ServerName mywebsite.com
        DocumentRoot /var/www/html

        ErrorLog ${APACHE_LOG_DIR}/mywebsite_error.log
        CustomLog ${APACHE_LOG_DIR}/mywebsite_access.log combined

</VirtualHost>

<VirtualHost *:80>
        ServerName myotherwebsite.com
        DocumentRoot /var/www/html

        ErrorLog ${APACHE_LOG_DIR}/myotherwebsite_error.log
        CustomLog ${APACHE_LOG_DIR}/myotherwebsite_access.log combined

</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Call me a noob, but I don't know if the reason it doesn't work is because I don't own the mywebsite.com and myotherwebsite.com domains but I thought it would follow the example in the book and the domains would be requested specifically through port 80 and add the resolve to my server IP further in this post it would be local no matter if I own the domains or not. I thought it could be the fact that they're pointing to the same /var/www/html file and that could be the problem. I enabled them before I tried to make it work, sudo a2ensite 000-virtual-hosts.conf && sudo systemctl reload apache2.

The book at one point says: "If you're using domain names with virtual hosts, then this will only work if you set up networking such that the domain name referenced in the file resolves to the IP address of your server. [...] If you're running your own DNS server, you would add the A record there." So I added this line to /etc/bind/net.local.lan and updated the serial number, otherwise the DNS wouldn't accept the new host.

mywebsite.com IN A 192.168.1.247

But I think the problem is I really don't know what I'm doing/doing wrong.

Here are the logs caught by /var/log/apache2/error.log, I don't know if those logs could include connection failures to mywebsite.com because they're supposed to be for the default .conf file but I'm sharing them in case you need them.

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
[Fri Dec 16 01:32:24.187718 2022] [mpm_event:notice] [pid 32022:tid 139897582640192] AH00489: Apache/2.4.41 (Ubuntu) configured -- resuming normal operations
in flag
Are you trying to connect to Apache on the local machine or on a different machine (or host) on the network?
Jimmy avatar
tz flag
I was trying to connect to Apache from another device that's on the same network. when I typed the IP:80 ( in this case `192.168.1.1:80`, `lenovo`'s IP referred to in the `/etc/bind/net.local.lan` file ) the default page works, but I tried typing `mywebsite.com:80` and it sent me to the actual .com instead. I can't really use the computer on which I've installed Apache since its screen doesn't really work so I connect to it using ssh.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.