gpt4 book ai didi

Apache 虚拟主机默认为 FQDN

转载 作者:行者123 更新时间:2023-12-01 13:47:20 24 4
gpt4 key购买 nike

我在我的 Apache 系统上设置了一个 VirtualHost,它恰好与服务器的 FQDN 同名。这是 FQDN:

root@mail:/etc/apache2/sites-available# hostname -f
mail.example.com

这是 .conf 文件的内容:

000-default.conf:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

example.com.conf:
<VirtualHost *:80>
ServerName mail.example.com
DocumentRoot /home/example/public_html
</VirtualHost>

现在我希望 mail.example.com 与 VirtualHost 匹配,因此使用 DocumentRoot/home/example/public_html。它没有。

运行 apache2ctl -S 产生:

*:80                   is a NameVirtualHost
default server mail.example.com (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost mail.example.com (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost mail.example.com (/etc/apache2/sites-enabled/abcarrental.nl.conf:1)

因此默认服务器是 mail.example.com,因此 DocumentRoot 是/var/www/html。

选择不同的 VirtualHost 名称(例如 webmail.example.com)并将 VirtualHostName 更改为 webmail.example.com 可以解决问题。

我已经浏览了 Apache NamedVirtualHost 手册页,但找不到解释。仅说明如果名称​​不 与任何虚拟主机匹配,则使用默认值。但如果 FQDM 等于请求的名称,则不会使用默认值。

这是设计使然的行为吗?

最佳答案

是的,当您从从系统本地主机名初始化的 VirtualHost 中省略 ServerName 时,这是设计使然,或者禁止从任何本地 IP 地址的反向 DNS 查找。

不幸的是,这个配置是由 debian/ubuntu 软件包创建的默认虚拟主机完成的。

事后看来——在一个包罗万象的(第一个列出的)虚拟主机中设置一个完全虚拟的 ServerName 被认为是更可取的。

关于Apache 虚拟主机默认为 FQDN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34953681/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com