gpt4 book ai didi

apache - 覆盖默认 Apache block 中的单个设置

转载 作者:行者123 更新时间:2023-12-02 11:22:26 24 4
gpt4 key购买 nike

在 debian 的默认 apache2 配置中,/etc/apache2/sites-enabled/000-default包含许多默认 VirtualHost 的设置:

<VirtualHost *:80>
# Many good settings here, among them:
CustomLog ${APACHE_LOG_DIR}/access.log combined
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
</VirtualHost>

在另一个配置文件中,我想覆盖其中一个, CustomLog设置,以便日志转到其他地方。我不想复制或弄乱所有其他设置,例如 ScriptAlias .但我还是希望它适用于 <VirtualHost *:80> .

那可能吗?

我试过的

我试着把这个放进去 /etc/apache2/sites-enabled/001-mylog :
<VirtualHost *:80>
CustomLog ${APACHE_LOG_DIR}/my.log combined
</VirtualHost>

那没有效果,大概是因为 apache 只查看第一个 <VirtualHost>部分,和 /etc/apache2/sites-enabled/000-default/etc/apache2/sites-enabled/001-mylog 之前加载.

相反,我尝试将相同的片段放入 /etc/apache2/conf.d/mylog , 在 /etc/apache2/sites-enabled/000-default 之前加载因为 /etc/apache2/apache2.conf有一个 Include conf.d/之前 Include sites-enabled/ .这确实覆盖了 CustomLog我想要的值(value)。但现在 ScriptAlias来自 /etc/apache2/sites-enabled/000-default不生效。

我想避免复制 /etc/apache2/sites-enabled/000-default 中的所有内容有效地创建默认 debian apache 配置文件的分支。

文档

Apache HTTP Server - core documentation有这个相当模糊:

When a request is received, the server first maps it to the best matching based on the local IP address and port combination only. Non-wildcards have a higher precedence. If no match based on IP and port occurs at all, the "main" server configuration is used.

If multiple virtual hosts contain the best matching IP address and port, the server selects from these virtual hosts the best match based on the requested hostname. If no matching name-based virtual host is found, then the first listed virtual host that matched the IP address will be used. As a consequence, the first listed virtual host for a given IP address and port combination is default virtual host for that IP and port combination.


<VirtualHost>行为不像 <Directory>
非常令人困惑,在我看来好像是 <VirtualHost>指令,只考虑一个匹配的实例。但是对于例如 <Directory>指令,它们被添加/组合,以便:
<Directory "/some/dir">
Options Indexes MultiViews FollowSymLinks
</Directory>
<Directory "/some/dir">
AllowOverride None
Order deny,allow
Allow from all
</Directory>

相当于:
<Directory "/some/dir">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all
</Directory>

但是这种机制不适用于 <VirtualHost> :-(

编辑 : 这和 Sharing configuration between several VHosts不一样,因为 debian 的默认 VirtualHost 不使用任何这些解决方案。但也许其他人可以从这个答案中找到灵感。

最佳答案

对于多个 vhosts'(virtual hosts') 定义,我得到了相同的难题。它们是否覆盖(重新定义)、重叠?或者里面还有其他隐藏的细节?

我找到了这个谜题的一些链接,如下所示:
https://www.thegeekstuff.com/2011/07/apache-virtual-host/
https://httpd.apache.org/docs/2.4/vhosts/examples.html

小心这些例子里面,我可以说虚拟主机的定义是不一样的(即使它们看起来一样)。区别主要在于服务器名称 内部定义。 Apache httpd服务器根据区分不同的vhost定义服务器名称 内部(每个虚拟主机定义),不是 <VirtualHost> 中列出的 IP 地址或端口号标题。

这个谜题不断出现,因为这个主题缺乏明确的解释(在网络上)。我希望这篇文章可以在某种程度上帮助缓解这个令人难以置信的问题。

关于apache - 覆盖默认 Apache <VirtualHost> block 中的单个设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20904278/

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