代码之家  ›  专栏  ›  技术社区  ›  gaf

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

  •  8
  • gaf  · 技术社区  · 8 年前

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

    但是AWS使用SNI,我无法使用mod_代理进行握手。

    我启用了以下设置

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

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

    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\u proxy和mod\u ssl没有将servername发送到远程https服务器,这可能是一个bug。

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

    我试图限制 SSLProxyProtocol 然而,不管怎样,sslv3警报握手失败日志仍然存在。

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

    1 回复  |  直到 8 年前
        1
  •  10
  •   gaf    8 年前

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

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

    指令信息:

    启用时,此选项将从传入 请求代理主机,而不是 代理传递线。

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