【问题标题】:Tomcat ignores X-Forwarded-Proto behind an Apache reverse proxyTomcat 忽略 Apache 反向代理后面的 X-Forwarded-Proto
【发布时间】:2020-04-28 06:24:22
【问题描述】:

我的 Tomcat 服务器位于 Apache 反向代理之后。尽管一切似乎都配置正确,request.isSecure() 返回false

Apache 配置

Apache 与 Tomcat 在同一台机器上运行。

ProxyPreserveHost On
RequestHeader set X-Forwarded-Proto "https"

Tomcat 阀门 (server.xml)

 <Valve className="org.apache.catalina.valves.RemoteIpValve" 
               internalProxies="127.0.0.1" 
               remoteIpHeader="x-forwarded-for" 
               proxiesHeader="x-forwarded-by" 
               protocolHeader="x-forwarded-proto" />

经过进一步检查,Tomcat 确实收到了带有httpsX-Forwarded-Proto 标头。但是上面的阀门肯定是配置错误。

【问题讨论】:

    标签: apache tomcat proxy reverse


    【解决方案1】:

    根据the RemoteIpValve docs,Tomcat 始终检查 req.getRemoteAddr() 是否适合阀门的internalProxiestrustedProxies

    确保该远程地址与您在阀门中设置的地址相符。如果代理使用 IPv6 地址 (0:0:0:0:0:0:0:1),127.0.0.1 将不起作用。

    相反,不要覆盖internalProxies,因为默认的正则表达式效果很好,例如:

    <Valve className="org.apache.catalina.valves.RemoteIpValve" 
                   remoteIpHeader="x-forwarded-for" 
                   proxiesHeader="x-forwarded-by" 
                   protocolHeader="x-forwarded-proto" />
    

    【讨论】:

      猜你喜欢
      • 2017-09-01
      • 1970-01-01
      • 2015-11-18
      • 2019-11-27
      • 2014-06-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多