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
EDIT
I changed my /etc/bind/net.local.net
$TTL 1D
@ IN SOA local.lan. exampleemail.local.lan. (
202212154; 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
mywebsite IN A 192.168.1.247
myotherwebsite IN A 192.168.1.247
I've made both website resolve to the same IP because in the book it says: "Any traffic coming into the server requesting "mywebsite" will be provided /var/www/mywebsite, the second example looks for traffic from "myotherwebsite" and directs hits to /var/www/myotherwebsite".
and disabled the default file in /etc/apache2/sites-enabled
that was taking the IP of the server.
Now the new page shows, but it doesn't make a difference when I type mywebsite
or mywebsite.local.lan
it doesn't find it but IP:80
works.
I still don't know how to type mywebsite
and reach the local page.
Results of the dig command
mywebsite.local.lan
; <<>> DiG 9.16.1-Ubuntu <<>> mywebsite.local.lan
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 17696
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;mywebsite.local.lan. IN A
;; Query time: 4 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Wed Dec 21 12:02:17 PST 2022
;; MSG SIZE rcvd: 48
myotherwebsite.local.lan
; <<>> DiG 9.16.1-Ubuntu <<>> myotherwebsite.local.lan
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 59264
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;myotherwebsite.local.lan. IN A
;; Query time: 8 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Wed Dec 21 12:02:19 PST 2022
;; MSG SIZE rcvd: 53
I get almost the same output from another computer on the network, just the udp
number changes.
/etc/bind/net.local.lan
as you can see in the linemywebsite.com IN A 192.168.1.247
to create a "local" resolution.