Apache VirtualHost 错误:主机名无效

sap*_*ish 5 virtualhost centos6 apache-2.2

对于这个 http.conf,我曾经很简单地设置一个 VirtualHost 来测试一个新的 php webapp:

NameVirtualHost *:80

<VirtualHost *:80>
        DocumentRoot /opt/webgrind/www
        ServerName webgrind
</VirtualHost>
<VirtualHost *:80>
        DocumentRoot /opt/opencart/www
        ServerName opencart
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

我只需要重新启动服务并访问:http://webgrind/http://opencart/(不更改任何内容/etc/hosts

但是服务器(CentOS 6)中发生了一些变化,现在error.log状态:

[error] avahi_entry_group_add_service_strlst("opencart") failed: Invalid host name
[error] avahi_entry_group_add_service_strlst("webgrind") failed: Invalid host name
Run Code Online (Sandbox Code Playgroud)

访问时http://webgrind/出现页面脱机错误。有任何想法吗?

服务器版本:Apache/2.2.15 (Unix) 服务器构建时间:2011 年 12 月 8 日 18:10:49

小智 5

由于这个问题是搜索“AH02415:[严格]无效主机名”时出现的第一个问题,我将添加一个答案来记录我今天浪费的时间,因为我的开发机器中的大多数虚拟主机都停止工作(例如 shop_one .web)。

我已将 Apache 更新到 2.4.16-18.1 版,显然HttpProtocolOptions现在默认为Strict,因此拒绝了其中包含“_”(下划线)的本地主机名(可能还有 OP 的主机名)。

我知道它们不是正确的主机名,但对于本地/个人使用永远不会伤害任何人,所以我添加了以下行:

HttpProtocolOptions Unsafe
Run Code Online (Sandbox Code Playgroud)

到我的 default-server.conf,生活又回到了原来的样子。也可以看看:

https://httpd.apache.org/security/vulnerabilities_24.html

https://unix.stackexchange.com/questions/340013/why-am-i-getting-400-bad-request/341306


小智 -1

在 apache 中配置虚拟主机并不会让服务器上的名称解析服务知道它,因此您要么必须更新 /etc/hosts,要么执行以下操作:

curl -H 'Host: webgrind' 127.0.0.1

覆盖默认行为。