当我通过 HTTP 在 apache2 服务器上执行 cURL 请求时,我收到的唯一响应是Invalid Host header
。但是,当使用 HTTPS 时,一切似乎都按预期工作。我确实为每个站点启用了重写以重定向到 HTTPS。这发生在所有子域中。虽然我做了一些挖掘,但我所能找到的都是与 webpack 相关的问题。
我正在apache2 2.4.52
奔跑ubuntu 22.04 LTS
。
这是我的主页的配置文件。
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/example.com
ServerName example.com
ServerAlias a.example.com
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
输出cURL --head --verbose http://example.com
* Trying <my-ip>:80...
* Connected to example.com (my-ip) port 80 (#0)
> HEAD / HTTP/1.1
> Host: example.com
> User-Agent: curl/7.84.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 404 Not Found
HTTP/1.1 404 Not Found
< Connection: Keep-Alive
Connection: Keep-Alive
< Content-Length: 9
Content-Length: 9
< Content-Type: text/plain
Content-Type: text/plain
< Date: Sun, 24 Jul 2022 16:09:03 GMT
Date: Sun, 24 Jul 2022 16:09:03 GMT
<
* Connection #0 to host example.com left intact
答案1
经过一番试验,我发现这是一个端口转发错误,因为它在本地解析正确,但在域中解析不正确。