问题原文
原帖链接 · McRaef · CC BY-SA 4.0
I have set up LAMP stacks on both Ubuntu 20.04 and Debian 10 running Apache 2.4.
The VirtualHost Files are identical as follows :
<VirtualHost localhost:80>
ServerAdmin webmaster@localhost
ServerName subdomain.localhost
ServerAlias www.subdomain.localhost
DocumentRoot /var/www/localhost/subdomain
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I have dissabled the default site and enabled the localhost site on both machines.
On Ubuntu i can just visit subdomain.localhost (and www.subdomain.locahost) via my browser. On Debian, however, I have to add an entry to the /etc/hosts file for every subdomain I'd like to create/use.
Why is that? Whats the difference between Debain and Ubuntu that causes that?
Am I able to configure Debian in a way so that I do not need to add an entry for every subdomain for localhost?
已采纳解答
原帖链接 · Stephen Ostermiller · CC BY-SA 4.0
Ubuntu is running the service systemd-resolved that maps localhost subdomains to your local IP address.
If you query the DNS using dig you will see that it gets the local IP address (127.0.0.1) from a SERVER running on a localhost IP address (127.0.0.53):
$ dig www.subdomain.localhost
...
www.subdomain.localhost. 0 IN A 127.0.0.1
...
;; SERVER: 127.0.0.53#53(127.0.0.53)
The configuration file that sets up the DNS servers to use (resolv.conf) specifies to use this local DNS server:
$ cat /etc/resolv.conf
...
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.
nameserver 127.0.0.53
You can verify that the systemd-resolved service is running with
$ sudo service systemd-resolved status
● systemd-resolved.service - Network Name Resolution
Loaded: loaded (/lib/systemd/system/systemd-resolved.service; enabled; vendor preset: enabled)
Active: active (running) ...
This service is available on Debian: https://manpages.debian.org/stretch/systemd/systemd-resolved.service.8.en.html but it is not enabled by default. You should be able to start the service on Debian by following the instructions from this Server Fault question: Is that possible for debian users to connect to network through systemd-networkd?
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
