Apache ProxyPass HTTPS 和带有 SNI 的远程服务器

gaf*_*gaf 6 apache mod-proxy mod-ssl

我想在 Apache 中使用反向代理将 AWS APIGateway URL 放在前面。原因是由于一个过程需要静态 IP 来在严格的防火墙后面提供服务,并且当前的基础架构已经安装了 mod_proxy。我希望实现的解决方案是简单地通过 mod_proxy 路由 https->https(apiGateway)。

但是.. AWS 使用 SNI,我无法让 mod_proxy 握手。

我启用了以下设置

<IfModule mod_ssl.c>
<VirtualHost *:443>
  ProxyPreserveHost On
  SSLProxyEngine On

  ProxyPass /api/1_0/ https://xxx.execute-api.eu-west-1.amazonaws.com/1_0/
  ProxyPassReverse /api/1_0/ https://xxx.execute-api.eu-west-1.amazonaws.com/1_0/
Run Code Online (Sandbox Code Playgroud)

以下日志在调试模式下可用

proxy_util.c(2020): AH00942: HTTPS: has acquired connection for (xxx.execute-api.eu-west-1.amazonaws.com)
proxy_util.c(2610): AH00962: HTTPS: connection complete to 52.x.x.x:443 (xxx.execute-api.eu-west-1.amazonaws.com)
AH01964: Connection to child 0 established (server domain.com:443)
AH02003: SSL Proxy connect failed
SSL Library Error: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
AH01998: Connection closed to child 0 with abortive shutdown (server domain.com:443)
AH01997: SSL handshake failed: sending 502
Run Code Online (Sandbox Code Playgroud)

如果我使用 openssl 连接,我可以演示类似的错误

openssl s_client -tls1_2 -connect xxx.execute-api.eu-west-
1.amazonaws.com:443
CONNECTED(00000003)
140735866254216:error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert 
handshake failure:s3_pkt.c:1494:SSL alert number 40
140735866254216:error:1409E0E5:SSL routines:ssl3_write_bytes:ssl handshake failure:s3_pkt.c:659:
Run Code Online (Sandbox Code Playgroud)

为 SNI 添加 -servername,导致有效连接

SSL handshake has read 3601 bytes and written 489 bytes
---
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES128-GCM-SHA256
...
Run Code Online (Sandbox Code Playgroud)

因此,我相信 mod_proxy 和 mod_ssl 不会将服务器名发送到远程 https 服务器,这可能是一个错误。

我正在运行 Ubuntu 14.04,服务器版本:Apache/2.4.7 (Ubuntu) 服务器构建:2017 年 9 月 18 日 16:37:54 OpenSSL 1.0.1f 2014 年 1 月 6 日

我试图限制 SSLProxyProtocolTLS1_2 和密码列表,但是无论如何 sslv3 警报握手失败日志仍然存在。

有没有人遇到过这个问题并且知道如何确保发送 SNI 值,或者这是 Apache 模块中的限制?

gaf*_*gaf 7

这是因为ProxyPreserveHost On在配置的早期设置。ProxyPreserveHost Off代理标签下的设置按预期完成:

<Proxy "https://xxx.execute-api.eu-west-1.amazonaws.com/1_0">
    ProxyAddHeaders off
    ProxyPreserveHost off
</Proxy>
Run Code Online (Sandbox Code Playgroud)

指令的相关资料:

启用后,此选项会将来自传入请求的 Host: 行传递给代理主机,而不是在 ProxyPass 行中指定的主机名。

此选项通常应关闭。它在特殊配置中最有用,例如基于代理的大众名称虚拟主机,其中原始主机标头需要由后端服务器评估。