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

标签 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/

以下日志在 Debug模式下可用
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

如果我使用 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:

为 SNI 添加 -servername 会导致有效连接
SSL handshake has read 3601 bytes and written 489 bytes
---
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES128-GCM-SHA256
...

因此,我认为 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 日

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

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

最佳答案

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

<Proxy "https://xxx.execute-api.eu-west-1.amazonaws.com/1_0">
    ProxyAddHeaders off
    ProxyPreserveHost off
</Proxy>

指令信息:

When enabled, this option will pass the Host: line from the incoming request to the proxied host, instead of the hostname specified in the ProxyPass line.

This option should normally be turned Off. It is mostly useful in special configurations like proxied mass name-based virtual hosting, where the original Host header needs to be evaluated by the backend server.

关于Apache ProxyPass HTTPS 和带有 SNI 的远程服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47718508/

相关文章:

apache - 简单后处理工具 : FATAL: Connection error (is Solr running at http://localhost:8983/solr/update ? )

java - 无法在hadoop中使用dfs创建目录

apache - 无法加载 'C:/Apache/Perl/site/lib/auto/Apache2/ModSSL/ModSSL.dll'

apache - "Using mod_ssl on Mac OS X"文档的当前版本?

java - Apache CXF 客户端代理设置

apache - XAMPP tomcat 服务未启动,错误为 "Tomcat Started/Stopped with errors, return code: 1"

https 站点的 Apache 反向代理给出 (70014) 找到文件结尾 :

linux - apache 使用 POST 数据代理 HTTPS 到 HTTP

apache - 如何使用 apache mod_proxy_balancer 基于 session 标识符启用粘性负载平衡

ssl - 安全的 Apache/PHP 登录页面?