当 X-Forwarded-For 和 X-Forwarded-Host 同时传递时,Apache 会中止连接

当 X-Forwarded-For 和 X-Forwarded-Host 同时传递时,Apache 会中止连接

X-Forwarded-For我正在尝试在 Nginx 反向代理后面运行 Apache。但是,如果请求中同时存在和标头,Apache 会中止连接X-Forwarded-Host。仅传递其中一个标头即可。使用httpie

$ http http://my-host:9000
HTTP/1.1 200 OK
...

$http http://my-host:9000 'X-Forwarded-For:172.16.16.1'
HTTP/1.1 200 OK
...

$ http http://my-host:9000 'X-Forwarded-Host:my-host:443'
HTTP/1.1 200 OK
...

$ http http://my-host:9000 'X-Forwarded-For:172.16.16.1' 'X-Forwarded-Host:my-host:443'
http: error: ConnectionError: ('Connection aborted.', BadStatusLine("''",))

这些请求在运行 Apache 的同一台机器上运行。从另一台机器运行有问题的请求是可行的:

some-other-machine $ http http://my-host:9000 'X-Forwarded-For:172.16.16.1' 'X-Forwarded-Host:my-host:443'
HTTP/1.1 200 OK

运行 Apache 的机器是一个 Vagrant 虚拟机,装有 Debian 8.6,有固定 IP私有网络。默认配置下运行的Apache版本是2.4.10。

我尝试禁用尽可能多的 Apache 模块,以下是仍然启用的模块:

$ apachectl -M
Loaded Modules:
 core_module (static)
 so_module (static)
 watchdog_module (static)
 http_module (static)
 log_config_module (static)
 logio_module (static)
 version_module (static)
 unixd_module (static)
 access_compat_module (shared)
 alias_module (shared)
 auth_basic_module (shared)
 authn_core_module (shared)
 authn_file_module (shared)
 authz_core_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 filter_module (shared)
 mime_module (shared)
 mpm_prefork_module (shared)
 negotiation_module (shared)
 rewrite_module (shared)
 rpaf_module (shared)
 setenvif_module (shared)

相关内容