![Apache 虚拟主机无法捕获所有请求](https://linux22.com/image/780398/Apache%20%E8%99%9A%E6%8B%9F%E4%B8%BB%E6%9C%BA%E6%97%A0%E6%B3%95%E6%8D%95%E8%8E%B7%E6%89%80%E6%9C%89%E8%AF%B7%E6%B1%82.png)
我有 80 端口请求重定向到 443,如下所示
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com mail.example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com mail.example.com
</VirtualHost>
但other_vhosts_access.log
其中有这样的条目
example.com:80 51.222.253.14 - - [14/Sep/2022:09:01:41 +0300]...
vm12345.example.com:443 37.104.179.26 - - [14/Sep/2022:08:59:54 +0300]...
为什么它们没有被命名的虚拟主机捕获?
答案1
由于您发布了不完整的配置,所以很难说,但可能是因为默认虚拟主机匹配请求example.com
而不是让虚拟主机处理这些请求example.com
。
检查(取决于 Linux 发行版)的输出apache2ctl -S
,或apachectl -S
或httpd -S
,并特别注意 Apache HTTP 认为默认虚拟主机
应该显示类似这样的内容:
VirtualHost configuration:
*:80 is a NameVirtualHost
default server api.example.com (/etc/httpd/conf.d/api.example.com.conf:1)
port 80 namevhost api.example.com (/etc/httpd/conf.d/api.example.com.conf:1)
alias www.api.example.com
port 80 namevhost corp.example.com (/etc/httpd/conf.d/corp.example.com.conf:1)
alias www.corp.example.com
port 80 namevhost admin.example.com (/etc/httpd/conf.d/admin.example.com.conf:1)
alias www.admin.example.com
ServerRoot: "/etc/httpd"
...
https://httpd.apache.org/docs/2.4/vhosts/details.html对虚拟主机匹配的工作原理进行了深入的讨论。